0

Im attempting to add a checked attribute in an input field in javascript that will be outputted as html

Here is my line..

var checked = ( <?php echo $original_delivery_date; ?> == json['dates_per_zone'][i]) ? "checked" : "";

I have verified that both json['dates_per_zone'][i] and $original_delivery_date are correct and displaying, but nothing is appearing.

Is that the correct syntax?

My final line is then...

html += '<input ' + checked + ' name="delivery_date" value="' + json['dates_per_zone'][i] + '">
2
  • And no console log errors? Commented Sep 3, 2013 at 9:39
  • "Nothing is appearing" - have you checked the output of that specific line? Commented Sep 3, 2013 at 9:41

2 Answers 2

1

It should be:

var checked = ( '<?php echo $original_delivery_date; ?>' == json['dates_per_zone'][i] ? "checked" : "" );

You're missing the quotes around the string that PHP prints.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that fixed it, Ill give this correct answer in 10 mins
0

Use Date as a string: Like this:

var checked = ('<?php echo $original_delivery_date; ?>' == json['dates_per_zone'][i] ? "checked" : "" );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.