I am trying to load some select options by using a few JS functions. I want to have one option selected by default if it is equal to a PHP variable defined before.
I receive an error:
Unexpected token
and I am sure I am doing something wrong with the syntax:
This is a section of my JS functions:
for(var i = 0; i < categories.length; i++){
select.options[i] = new Option(categories[i].val,categories[i].id);
if (select.options[i].text== <?php echo '$categoriesSelect'; ?>)
{
select.options[i].selected=true;
}
}
The variable $categoriesSelect is defined before the JS. Thank you!
"json_encode($categoriesSelect)"$categoriesSelectvariable contain, since you pass it throughjson_encode()(which will return a json object, and not a single value)?