The following works well:
var options = '<select><option value ="Unknown">Unknown</option><option value ="Yes">Yes</option><option value ="No">No</option><option value ="Both">Both</option></select>';
alert(options)
However, if that string is produced via a PHP foreach, the variable options is not recognized, hence I cannot use with JS. For example:
<?php foreach($pickListFields as $field_id => $options): ?>
<?php
$options_array = explode("\n", $options);
$options_select = '<select>';
foreach($options_array as $k => $option) {
$options_select .= '<option value ="' . $option . '">' . $option . '</option>';
}
$options_select .= '</select>';
?>
var options = '<?= $options_select ?>';
<?php endforeach; ?>
The above variable options produced, does not work, even though when I see the source code with Firefox I can see that var options is:
var options = '<select><option value ="Unknown">Unknown</option><option value ="Yes">Yes</option><option value ="No">No</option><option value ="Both">Both</option></select>';
Why then it cannot be used, if it is the same as the first example? I cannot alert that, or assign it to a field, but I can with the first example.