Hints
In this Example explained about Select Combobox validation using Javascript.
options attribute returns all the options of select component and selectedIndex returns the current option index. Index started with 0 likewise for 0,1,2,3 to <empty>,Siva,Raja and Roja respectively
|
Username:
<select name="slt_usernames" id="slt_usernames">
<option></option>
<option value="1001">Siva</option>
<option value="1002">Raja</option>
<option value="1003">Roja</option>
</select>
<button onclick="javascript:validate();">Validate</button>
|
function validate(){
if (document.getElementById("slt_usernames").selectedIndex == 0){
alert("Select the username");
}
else {
alert(document.getElementById("slt_usernames").options[document.getElementById("slt_usernames").selectedIndex].value);
}
}
|