Wednesday, March 14, 2018

javascript - How to set default value for HTML select?




I have a HTML select like this:






and I have a variable named temp in my JavaScript:



var temp = "a";



Now I want to set the value of the option that is equal to temp as default value for my select.



How can I do it?


Answer



$(function() {
var temp="a";
$("#MySelect").val(temp);
});




No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...