We can use the value
property of the selectbox
to get the selected value of the dropdown list.
In the above code:
selectbox
with three options (one
, two
, and three
). dropdownList
and assign the created selectbox
as the value.selectbox
. The assigned function will be executed when the value of the selectbox
changes. Inside the function, we get the value
property of the select box and print it. The value
property denotes the selected value of the selectbox
. If we want to get the selected option text, then we should use the selectedIndex
property of the selectbox
. The selectedIndex
property denotes the index of the selected option. Once we get the selected index, we can access the selected option. From that, we can get the value and text of the option by accessing the value
and text
property, respectively.
In the above code:
selectbox
with three options (one
, two
, and three
). dropdownList
and assign the created selectbox
as the value.selectbox
. The assigned function will be executed when the value of the selectbox
changes. selectedIndex
property of the select box and print it. It returns the index of the selected option element of the selectbox
.selectedIndex
property, we get the selected option of the selectbox
and store it in the variable with name selectedOption
. value
and text
property of the selectedOption
and print it.