Christopher Schene
asked on
What is the Javascript code to set a select index
What is the Dom code to set this select index
<SELECT onchange="someJavaScriptco de" size=1 name=Options1 index="2"><OPTION selected>Actions<OPTION>Vi ew<OPTION value=P>Print<OPTION value=F>Fax</OPTION></SELE CT>
I tried
document.forms.listing.Opt ions1.inde x = 2;
without success
Thanks: I need a fast answer: 300 points!
<SELECT onchange="someJavaScriptco
I tried
document.forms.listing.Opt
without success
Thanks: I need a fast answer: 300 points!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
document.forms[0].Options1 .options[d ocument.fo rms[0].Opt ions1.sele ctedIndex] .selected= false;
document.forms[0].Options1 .options[n ewIndex].s elected=tr ue;
document.forms[0].Options1
as gjutras suggested, but some browser are still too stupid to handle the DOM, they sometimes work with:
document.forms[0].Options1 .options[d ocument.fo rms[0].Opt ions1.sele ctedIndex] .setAttrib ute('selec ted',false );
document.forms[0].Options1 .options[n ewIndex].s etAttribut e('selecte d',true);
Keep in mind that forms[0] depend on your number of forms in the page, I'd use an id= attribute for the select tag and the get this object with document.getElementById().
document.forms[0].Options1
document.forms[0].Options1
Keep in mind that forms[0] depend on your number of forms in the page, I'd use an id= attribute for the select tag and the get this object with document.getElementById().
ASKER