Sunday, May 12, 2024
113
rated 0 times [  116] [ 3]  / answers: 1 / hits: 29920  / 11 Years ago, wed, january 1, 2014, 12:00:00

How would I alert out that the selection must not be be blank in plain javascript?



Here is my code for my option menu:



            <div class=interest>
<label for=interest>Interest Area *</label>

<select name=interest>
<option value=blank></option>
<option value=option1> EXAMPLE 2 </option>
<option value=option2> EXAMPLE 3 </option>
<option value=option3> EXAMPLE 4 </option>
</select>
</div>


Thanks in advance


More From » html-validation

 Answers
61
document.getElementsByName('interest')[0].onchange = function() {
if (this.value=='blank') alert('Select something !');
}


or in a submit handler or similar, just check the value



if ( document.getElementsByName('interest')[0].value == 'blank' )
alert('Select something !');

[#73442] Tuesday, December 31, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
juancarlos

Total Points: 580
Total Questions: 105
Total Answers: 103

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
;