In my experience there's nothing wrong with that approach. I believe that in very early browsers - before document.getElementById you may have needed to use the:
Code:
selectElement.options[selectElement.options.selectedIndex].value
And that still works, and sometimes, depending upon the circumstances you might want or even need the selectedIndex for your code. So it's good to know that it exists and how to access it via javascript.
But again, as far as I know, any browser that does document.getElementById will access the value directly. If that's all you need, that's all you have to do:
Code:
selectElement.value
BTW, that page on w3schools assumes there are no other option elements on the page before the ones you're interested in. If there were, the incorrect value would be returned. But if you do it like I have it (either example above), the correct value will be returned regardless of other option elements on the page.
Bookmarks