Page 1 of 1

Event handlers in java script

Posted: Fri Feb 13, 2009 12:54 am
by kousalya
]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?

Re: Event handlers in java script

Posted: Fri Feb 13, 2009 8:30 am
by VladSun

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> 

Re: Event handlers in java script

Posted: Fri Feb 13, 2009 4:11 pm
by pickle
Unfortunately, IE only fires the change() event after the element loses focus - you'll likely need to use mouseup.

Re: Event handlers in java script

Posted: Fri Feb 13, 2009 7:05 pm
by VladSun
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:

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;}
You can notice ther is no "blur" event.