Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to check if an item is selected from an HTML drop down list with javascript js

// See the below HTML first
/*
<select id="cardtype" name="cards">
    <option value="mastercard">Mastercard</option>
    <option value="maestro">Maestro</option>
    <option value="visadebit">Visa Debit</option>
</select>
*/

// Javascript Solution
var select = document.getElementById("cardtype");
var selectedValue = select.options[select.selectedIndex].value;

// Courtesy: Sachin - https://stackoverflow.com/users/1041642/sachin

Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #check #item #selected #HTML #drop #list #javascript #js
ADD COMMENT
Topic
Name
8+7 =