During the programming process, the value of the drop -down list box is often obtained from the value in Option, but there are also when there is a value displayed in the page, for example Option> "Showtext", how should we get it? The method is very simple, the specific code is as follows:
Copy code code as follows:
<script type = "text/javascript">
Function A (Object) {
Alert (Object);
}
</script>
<!-Get the display value->
<select onChange = "a (this.Options [this.Selectindindex] .innertext);">
<option value = "value-a"> text-a </option>
<option value = "value-b"> text-b </option>
</select>
<!-Get the value of Value->
<select onChange = "a (this.Options [this.SelectIDIDEX]. Value);">
<option value = "Value-C"> Text-C </option>
<option value = "Value-D"> Text-D </option>
</select>
Function isselect (selectpress) {
// var select = document.GetelementByid ("MySelect").
var selectValue = selectpress.options [selectpress.selectExDex]. Value; // Display value of valve 0, 1, 2
var selectValue2 = selectpress.options [selectpress.SelectEdindex] .innertext; // Display the displayed value of the displayed value (Shanghai, Beijing)
// alert (selectValue);
// alert (selectValue2);
If (selectValue == "-1") {{
Alert ("Please select the city, the form submission of the form is rejected!")
Return;
}
else {
document.GetelementByid ('Form1'). submit (); // Form forms submit
}
}
<select onChange = "isselect (this);" id = "mySelect">
<option value = "-1">-Please select- </option>
<option value = "0"> Beijing </option>
<option value = "1"> Shanghai </option>
<option value = "2"> Wuhan </option>
</select>