Javascript onfocus / alerts help :)

Associate
Joined
15 Feb 2006
Posts
1,872
Location
hell
Hi guys

I'm trying to learn more about javascript at the moment and am trying to fire an alert every time a form field is focused on.

I've created this code.
Code:
	function setup()
	{
	
	var formfields = document.getElementsByTagName("input");
	formfields[0].addEventListener("focus",fireevent,false);
	
	}
	function fireevent()
	{
	alert(this.id);
	return false;
	}

<body onload="setup()">

I have two problems:

Firstly, the alert fires correctly on the first input... however, when I press OK, it keeps firing! how do I make it only fire once?

Second problem, how can I make it fire on ALL inputs? You'll see I've done the following: formfields[0]. with the [0] indicating the first form input. However, I've only done this, as without selecting one input, it doesn't work at all...

Any help would be greatly appreciated
 
Back
Top Bottom