Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  31] [ 3]  / answers: 1 / hits: 17471  / 10 Years ago, mon, september 15, 2014, 12:00:00

I want to show a warning message if a user selects a specific option, but the warning isn't appearing. How can I modify my code so that this works correctly? Here is a demo on jsFiddle which reproduces the problem?



HTML :



<input type=text id=mail_address/>
<select>
<option value='google.com'>google.com</option>
<option onClick=warningaa() value=''>Don't send mail</option>
</select>


JS:



function warningaa() {
alert('If you choose this option, you can not receive any information');
}

More From » html

 Answers
4

You can not use on click action in dropdown option. One solution is to use change on select element:



html



<input type=text id=mail_address />
<select onchange=warningaa(this);>
<option value='google.com'>google.com</option>
<option value='error'>error</option>
</select>


js



function warningaa(obj) {
if(obj.value == error) {
alert('If you choose this option, you can not receive any infomation');
}
}


fiddle


[#69453] Friday, September 12, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shekinah

Total Points: 699
Total Questions: 112
Total Answers: 110

Location: Philippines
Member since Sat, Jul 11, 2020
4 Years ago
;