How to make drop down option selected in javascript


Posted on 18 Dec 15 by Vickey

With the help of below javascript code we can select a dropdown option dynamically.I have a dropdown box with id exp_year

<select id="exp_year">

<option value="2001"></option>

<option value="2002"></option>

<option value="2003"></option>

<option value="2004"></option>

<option value="2005"></option>

var exp_year = document.getElementById("exp_year");

for (var i = 0; i < exp_year.options.length; i++) {

	if (exp_year.options[i].value== 2004) {
		exp_year.options[i].selected = true;


If this post help you reduce time to develop, you can help me to maintain this website :)