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? Quote Link to comment Share on other sites More sharing options...
nogray Posted November 10, 2011 Share Posted November 10, 2011 <?php echo str_replace("'", "\\'", $height); ?> (not tested) Quote Link to comment Share on other sites More sharing options...
sleepingpeace Posted November 10, 2011 Author Share Posted November 10, 2011 Excellent! Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.