I have overriden the click event on my select tag. When I click on my select tag as default the option list is showing. But I have to customize that listing and do some other work when I click on select tag.
How can I achieve this?
please see below code :
<!DOCTYPE html>
<html>
<body>
<select id="selectId">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<script>
document.getElementById("selectId").onclick = function () {
alert("second event");
}
</script>
</body>
</html>
Here both event get fired, but I want only the second event.
You can't override the
select
elementonClick
because it doesn't have one. When you click on aselect
the browser handles it with magic that you can't temper with. You can't simulate a click on it either.The only things you can do to a select are:
size
property. You can change it to1
to force it to close, but you will see an ugly flicker.hidden
property on all childoption
elements totrue
You can fake it, something like this:
http://jsfiddle.net/BupuU/3/
HTML:
Javascript:
CSS:
This is only a starting point. You can build from here.