cve60069 Posted June 30, 2012 Share Posted June 30, 2012 Hello I am trying to dynamically alter the contents of a drop-down menu. For example: <select id="contents><option>item 1</option><option>item 2</option><option>item 3</option></select> I want to change the value of each of the options from within a script. I am assuming I will use something like document.getElementById("contents").innerHTML=x, where x is a line of text; but I do not how to access the contents of each <option> Am I on the right track, please? Regards Link to comment Share on other sites More sharing options...
Guest So Called Posted June 30, 2012 Share Posted June 30, 2012 (edited) I want to change the value of each of the options from within a script. Why not this? It may not be elegant but it seems to solve the problem of getting each option separately. <select><option id="item1">item 1</option><option id="item2">item 2</option><option id="item3">item 3</option></select> Edited June 30, 2012 by So Called Link to comment Share on other sites More sharing options...
dsonesuk Posted June 30, 2012 Share Posted June 30, 2012 Use '.options' as described here http://w3schools.com/js/tryit.asp?filename=try_dom_option_settext x.options.[0] equals first optionx.options.[1] equals second option and so on Link to comment Share on other sites More sharing options...
cve60069 Posted June 30, 2012 Author Share Posted June 30, 2012 Thanks for the advice. I tried the array for options but used () and not [ ]. . Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now