]Hai All,
I am working with combo boxes. When a user selects an item in a combo box, how do i identify whether an item is selected or not. when an item is selected the flag should be set to true if not it should be false. Which event handler should i use?
Event handlers in java script
Moderator: General Moderators
Event handlers in java script
Re: Event handlers in java script
Code: Select all
<select id="combo" name="combo"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option></select> <script language="JavaScript"> var combo = document.getElementById('combo'); combo.onchange = function (){ alert(this.value);} </script> There are 10 types of people in this world, those who understand binary and those who don't
Re: Event handlers in java script
Unfortunately, IE only fires the change() event after the element loses focus - you'll likely need to use mouseup.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Event handlers in java script
I tested it in IE8 and ehen I opened the page IE poped up a warning, I clicked yes and the following HTML/JS worked as expected:
You can notice ther is no "blur" event.
Code: Select all
<select id="combo" name="combo"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option></select> <div id='d'></div> <script language="JavaScript"> var combo = document.getElementById('combo');var d = document.getElementById('d'); combo.onchange = function (){ d.innerHTML = this.value;}There are 10 types of people in this world, those who understand binary and those who don't