<html>
<head>
</head>
<script>
function ClickFun() {
document.getElementById("print").innerHTML = 100;
}
function ClickFunction() {
document.getElementById("print").innerHTML = 200;
}
function Click() {
document.getElementById("print").innerHTML = 150;
}
function hello() {
alert("you clicked the list");
}
</script>
<body>
<select>
<option onclick="ClickFunction();">Chrome</option>
<option onclick="Click();">Mozilla</option>
<option onclick="ClickFun(); hello();">Eclipse</option>
</select>
<p id="print"></p>
</body>
</html>
Asked
Active
Viewed 97 times
-2

Rahul Tripathi
- 168,305
- 31
- 280
- 331

Soumya
- 1
-
1Possible duplicate of [jquery select option click handler](http://stackoverflow.com/questions/5749597/jquery-select-option-click-handler) – Alexander O'Mara Dec 28 '15 at 07:51
-
1Don't use click events for select options, use the change event. – Alexander O'Mara Dec 28 '15 at 07:52
1 Answers
0
As suggested by Alexander, use onchange event on select option.
<html>
<head>
</head>
<script>
function print(){
switch(document.getElementById("browser").value){
case "c":
document.getElementById("print").innerHTML = 100;
break;
case "m":
document.getElementById("print").innerHTML = 200;
break;
case "e":
document.getElementById("print").innerHTML = 150;
default:
alert("you clicked the list");
}
};
</script>
<body>
<select id="browser" onchange="print()">
<option value="c">Chrome</option>
<option value="m">Mozilla</option>
<option value="e">Eclipse</option>
</select>
<p id="print"></p>
</body>
</html>

SathishPurushothaman
- 81
- 1
- 1
- 6