Sunday 5 November 2017

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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...