Online Shopping : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to
Did You Find This Entry Useful?

14 of 29 people (48%) answered Yes
Recently 2 of 10 people (20%) answered Yes


How do I assign an onchange handler to a node created via DOM methods?

Apr 5th, 2008 20:32
ha mo, sven vahar, Dan,

This works with IE & NS6+. Remeber, onchange fires when element loses
focus so you have to move focus from the input to see whoa() in action.
	<title> * </title>
	<script language="JavaScript" type="text/javascript">
	function init(){
		var x = document.getElementsByTagName('body')[0];
		var y = document.createElement('form');
		var z = document.createElement('input');
		z.onchange = whoa;
	function whoa (){
		alert('yea, you changed me');
	// -->
<body onload="init()">