I am using the following line of code to dynamically set the default selection of a selection box in html with jQuery
var y=...a value from the DB;
this.$(".status option[value=y]").attr("selected", "selected");
However, this only work if I replace it manually by saying option[value=3], I can’t use a variable here.
I have already made sure what’s from the DB is one of the option.
Thanks
The simplest way to do this is to use the jQuery
valmethod:If you want to continue selecting the correct
optionand setting theselectedattribute, then @redsquare’s answer should do the trick, but note that you can also usepropinstead ofattrif you’re using a later version of jQuery.