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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -