I would like to programmatically select an <option> using JavaScript. I only have the value of the <option>, how do I get the object with just this data using JavaScript.
Let me show an example:
Now how do I select the <option> with a value of "pqr" using JavaScript. With index it can be done like this:
But I don't have the index, I only have the value.
Originally posted by Satou kurinosuke: If you give your option tags a "name" or an "id", you can access each of them like: document.form1.mySelect.options['pqr'].selected = true
Thanks Satou
One correction, to get an HTML Object using id, it's: