sleepingpeace Posted November 10, 2011 Share Posted November 10, 2011 I'm retrieving a height value from a database as a string that is valued as 5'6", 6'11", etc... My code is this $('select[name=height] option').each(function () { if ($(this).val() == '<?php echo $height ?>') $(this).attr('selected', 'selected'); }); What I'm doing here is going through each option in a select dropdown and comparing the retrieved value from the database to the option's value and auto-selecting that option when the match is found. The issue is that the height value, say 5'6", contains a single and double quote which terminates the string in the evaluation prematurely. What is the best option to fix this? Link to comment https://forums.phpfreaks.com/topic/250895-jquery-php-string-literals/ Share on other sites More sharing options...
nogray Posted November 10, 2011 Share Posted November 10, 2011 <?php echo str_replace("'", "\\'", $height); ?> (not tested) Link to comment https://forums.phpfreaks.com/topic/250895-jquery-php-string-literals/#findComment-1287192 Share on other sites More sharing options...
sleepingpeace Posted November 10, 2011 Author Share Posted November 10, 2011 Excellent! Thanks! Link to comment https://forums.phpfreaks.com/topic/250895-jquery-php-string-literals/#findComment-1287196 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.