How to change options in select tag in javascript using console? -
this question has answer here:
<select name="ethinicity" > <option value="type1">asian</option> <option value="type2">african</option> <option value="type3">caucasion</option> <option value="type4">hispanics</option> <option value="type5">other populated groups</option> </select>
i using
document.getelementsbyname("ethinicity").value="type2"
to change value,but donot work in way,why can't this? , give me other way donot want put in form
, changing like
document.formname.ethinicity.value="type2"
thanks in advance!
you can this:
document.getelementsbyname("ethinicity")[0].selectedindex = 1;
you should give select id this:
<select id="ethinicity" name="ethinicity" > document.getelementbyid("ethinicity").selectedindex = 1;
Comments
Post a Comment