简写如果否则混合PHP与JavaScript无法正常工作

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] + '">

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.

Use Date as a string: Like this:

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