Wednesday, 14 March 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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...