There are lots of ways to set a dropdown’s selection but the easiest would be to set the dropdown’s value with a value. Provided you used an id to access the dropdown object, do this.
document.getElementById('dropdown').value = 'one';
If your dropdown looks like this,
|
1 2 3 4 |
<select id="dropdown"> <option value="one">One</option> <option value="two">Two</option> </select> |
Then using the Javascript code above, the selection will highlight One. The value attribute must be present. If not, then the dropdown item’s label name gets used. If you wish to use other means, you can check out selectedIndex.
jy is ‘n poes, vestaan jy dat jy ‘n doos poes is
Superb solution!
@shiba: thanks
thank you so much. i have been strugling with this all day !!!! the solution is elegant.
@juan: you’re welcome
Thank you for such a simple solution. I’ve been searching for about an hour or two. All the solutions I’ve seen were overly complex. This is exactly what I was looking for and worked like a charm.
EASY . SIMPLE. LOVE IT. LOVE U
XOXOXOXO
SEXY PROGRAMMER XO
HAHAHAHAHAHAHAHAHA @ POES