Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert can't be called in chrome [duplicate]

I met an error when i use chrome (it's ok in firefox). It's my code, very simple:

<html><head></head>
<body>
<select>
        <option onclick="alert('abc');">A</option>
        <option>B</option>
</select>         
</body>
</html>

In firefox, when i click on option A, it will be show an alert('abc'). But in chrome, it doesn't run. Can i change something in setting of chrome?

Any suggestions?

Thanks!!!

like image 417
Trong Lam Phan Avatar asked Dec 05 '25 05:12

Trong Lam Phan


2 Answers

use onchange event provided by html select,

Example : alerts the selected option

<select onchange="alert(this.value)">
        <option>A</option>
        <option>B</option>
</select>
like image 87
user183781 Avatar answered Dec 06 '25 18:12

user183781


You need to use the onchange event

http://jsfiddle.net/WB3Q9/

When a user selects an option, the value of the select element changes, thus firing the onchange event and whatever function you binded to it

<select onchange="alert('The Value is ' + this.value)">

like image 41
Zone6 Avatar answered Dec 06 '25 17:12

Zone6



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!