Get Combobox value Using JavaScript: Combo box or dropdown value can be accessed by following two methods, one you can access it using its index counter and second you can access it using selected index text.
JavaScript get Combobox selected Index text:
<select name="fruits" id="fruits"> <option value="Apple">Apple</option>
<option value="Apricot">Apricot</option>
<option value="Asparagus">Asparagus</option>
<option value="Fig">Fig</option>
<option value="Avocado">Avocado</option>
<option value="Banana">Banana</option>
<option value="Clementine">Clementine</option>
<option value="Honeydew melon">Honeydew melon</option>
</select>
<button onclick="javascript:GetComboBoxValue();">Validate</button>
<script>
function GetComboBoxValue(){
var CmbObject=document.getElementById("fruits")
var fruitName=CmbObject.options[CmbObject.selectedIndex].value;
// get valus using selectedIndex alert('Your selcted fruit is - '+ fruitName ); } </script>
// get valus using selectedIndex alert('Your selcted fruit is - '+ fruitName ); } </script>
No comments:
Post a Comment