Reputation: 2012
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] + '">
Upvotes: 0
Views: 63
Reputation: 4523
Use Date as a string: Like this:
var checked = ('<?php echo $original_delivery_date; ?>' == json['dates_per_zone'][i] ? "checked" : "" );
Upvotes: 0
Reputation: 23590
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.
Upvotes: 1