Jump to content

Jquery & PHP String Literals...


sleepingpeace

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.