Method analysis of javascript to obtain select values
- 2020-06-22 23:53:34
- OfStack
This article illustrates how javascript gets the select value. Share to everybody for everybody reference. The specific analysis is as follows:
1. Get the displayed Characters
document.getElementById("bigclass").options[window.document.getElementById("bigclass").selectedIndex].text
2. Get id in the database
window.document.getElementById("bigclass").value
3. Get the index id assigned by the select group
window.document.getElementById("bigclass").selectedIndex
Example:
<select name="bigclass" id="bigclass" onChange="javascript:updatePage2();">
<option value="" selected="selected">ajax The experiment </option>
<option value="4"> I'm fit for the city </option>
</select>
Use:
document.getElementById("bigclass").options[window.document.getElementById("bigclass").selectedIndex].text
The result is: I fit the city ha
Use:
window.document.getElementById("bigclass").value
The answer is: 4
Use:
window.document.getElementById("bigclass").selectedIndex
The answer is: 1
I hope this article has been helpful for your javascript programming.