Event handlers in java script

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
kousalya
Forum Newbie
Posts: 4
Joined: Mon Feb 02, 2009 2:25 am

Event handlers in java script

Post 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?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Event handlers in java script

Post 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> 
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Event handlers in java script

Post by pickle »

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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Event handlers in java script

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply