Knowledge Walls
John Peter
Pune, Maharashtra, India
How to validate multiselect combobox in Javascript and HTML with Example
7758 Views
HTML
Username:<br />
<select name="slt_usernames" id="slt_usernames" multiple>
 <option value="1001">Siva</option>
 <option value="1002">Raja</option>
 <option value="1003">Roja</option>
 <option value="1004">Lakshanya</option>
 <option value="1005">Vidhyaa</option>
</select>
<br /><br />
<button onclick="javascript:validate();">Validate</button>
JAVASCRIPT
function validate(){
    var n = document.getElementById("slt_usernames").options.length;
    for (var i = 0;i < n; i++){
        if (document.getElementById("slt_usernames").options[i].selected === true)
            alert(document.getElementById("slt_usernames").options[i].value+" is selected.");
        else
            alert(document.getElementById("slt_usernames").options[i].value+" is not selected.");
    }
}
OUTPUT 
DEMO 
Best Lessons of "Good Javascript Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details