How do I get the value of option of the select drop down box without and with a value attribute

  • 2020-03-26 23:46:38
  • OfStack

How to get the value of the select drop-down box:
1. When the option in the drop-down box has no value attribute
 
<select id="param1"> 
<option> Student id </option> 
<option> The name </option> 
<option> age </option> 
</seclect> 
<script> 
window.onload = funciton(){ 
var param = document.getElementById("param1"); 
param.onchange = getParam(){ 
var text = param.value; 
} 
} 
</script> 

2. When the option in the drop-down box has a value attribute
 
<select id="param1"> 
<option> Student id </option> 
<option> The name </option> 
<option> age </option> 
</seclect> 
<script> 
window.onload = funciton(){ 
var param = document.getElementById("param1"); 
param.onchange = getParam(){ 
var selectIndex = param.selectIndex; //Gets the lead number of the option
var text = param.options[selectIndex].text; 
</script> 

Related articles: