Good day!
How can i make the first value in my array e.g currency[0] be the default value of my drop down list?
My code is as follows:
function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
function initAll(){
var currency = new Array("Peso","Dollar","Euro","Yen","CAD");
var rate = new Array("0.02319", "1", "1.416", "0.012241", "1.027");
for (var i=0; i < currency.length;++i){
addOption(document.drop_list.Month_list, currency[i开发者_如何学编程],rate[i]);
}
}
I want the default value be the first array...
<FORM name="drop_list">
<select name="Month_list">:
<Option value="" >-----</option> //what could i insert here?
</select><br>
</form>
You're help would be highly appreciated.
In the end of initAll function put :
document.drop_list.Month_list.selectedIndex=1;
Use Adelave's solution if you decide to have the first option as "-----". You may altogether remove the hard-coded option "-----" and select drop-down would be auto-selected with the first option in the drop-down box.
精彩评论