I'm using an HTML dropdown box like this: <select name="bla"> <option value='1'>aaa</option> <option value='2'>bbb</option> <option value='3'>ccc</option> </select> if I want to get the selected option's value, I use something like this: document.frm.bla.value; What I would like to know is whether there is a way to retrieve the text associated with that option. I know that the first option's value is 1, for example, but can I write a script that will get the text - aaa?
Try this, it's working for me on FireFox and explorer: <html> <head> <script type="text/javascript"> function f_selected(p_index) { var v = document.getElementsByTagName( "option" )[p_index]; alert( "value='" + v.value + "', text='" + v.text + "'" ); } </script> </head> <body> <select id="bla" onchange="f_selected(this.selectedIndex)"> <option value='1'>aaa</option> <option value='2'>bbb</option> <option value='3'>ccc</option> </select> </body> </html> Code (markup):