I have a select
html-tag with several options
.
Here is an example:
<select id="mySelect1" size="4" style="width:100px;">
<option value="AUS"
name="Australia"
city="Canberra"
>Australia</option>
<option selected value="CAN"
name="North America"
city="Ottawa"
>Canada</option>
<option value="GRC"
name="Europe"
city="Athens"
>Greece</option>
<option value="JPN"
name="Asia"
city="Tokyo"
>Japan</option>
</select>
I know how to alert
the value
of the selected option:
alert(mySelect1.options[mySelect1.options.selectedIndex].value);
But when I try to alert
the city
or even the name
of the selected option I fail, with almost the same code:
alert(mySelect1.options[mySelect1.options.selectedIndex].city);
alert(mySelect1.options[mySelect1.options.selectedIndex].name);
Is it possible to get any attribute
and the text
from the selected option
in pure javascript?