Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event Handling Weirdness 1

Status
Not open for further replies.

dwarfthrower

Programmer
Apr 22, 2003
1,625
AU
Howdy, I was wondering whether anyone else had run across this little gem of strangeness. In IE, some events don't seem to be handled if another event fires beforehand.
Code:
<html>
<head>
<script>
function do_link_onclick(){
 alert("do_link_onclick() fired");
}
function do_field_onchange(){
 alert("do_field_onchange() fired");
}
</script>
</head>
<body>
<textarea onchange="do_field_onchange()">Change this value</textarea>
<br>
<a href="#" onclick="do_link_onclick()">Now Click Here</a>
</body>
</html>

In Firefox, if you edit the value in the textarea, then click on the link, you get the notification of the onchange event firing, then the notification of the link's onclick event firing. Do the same in IE and only the textarea's onchange event fires.

Has anybody got any ideas about how to get IE to behave rationally in this instance?

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 

Both events do fire - depending on how you care to show them. In your case, the alert is somehow interfering with the events. Change your code to this to see what I mean:

Code:
<html>
<head>
<script type="text/javascript">
	function do_link_onclick(){
		document.getElementById('wibble').value += '\ndo_link_onclick() fired';
	}

	function do_field_onchange(){
		document.getElementById('wibble').value += '\ndo_field_onchange() fired';
	}
	</script>
</head>
<body>
	<textarea onchange="do_field_onchange()">Change this value</textarea><br>
	<a href="#" onclick="do_link_onclick()">Now Click Here</a><br>
	<textarea cols="50" rows="10" id="wibble"></textarea>
</body>
</html>

You will see that without the focus being lost from the link (which the alert will do), both events fire as expected.

Hope this helps,
Dan
 
Cheers Dan... that works a treat... I'll use some alternate method for feedback to the user.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top