Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: SV: Re: SV: Return Key/Enter Key Event Handler


Message #1 by "Robert Nyman" <robert.nyman@c...> on Tue, 29 Oct 2002 10:54:45 +0100
With your code (to make it easy), give all input fields/text boxes an
index no attribute:

function EnterHandler(){
	if(event.keyCode =3D=3D 13){
		var intNewIndexFocus =3D
parseInt(this.getAttribute("indexNo"), 10) + 1;=09
		var arrInputFields =3D
document.getElementById("myform").getElementsByTagName("input");
		for(var i=3D0; i<arrInputFields.length; i++){
			var oInput =3D arrInputFields[i];
			if(oInput.getAttribute("type") =3D=3D "text" &&
parseInt(oInput.getAttribute("indexNo"), 10) =3D=3D intNewIndexFocus){
				oInput.focus();=09
			}
		}
	}
}

<form name=3D"myform">
	<font size=3D"2">SurName</font><br>
	<input name=3D"surname" type=3D"text" indexNo=3D"1"
onKeyDown=3D"EnterHandler(this); event.returnValue =3D false">
	<font size=3D"2">FirstName</font><br>
	<input name=3D"firstname" type=3D"text" indexNo=3D"2"
onKeyDown=3D"EnterHandler(this); event.returnValue =3D false">
</form>


What this function does is that it checks if the enter key was pressed
and then the indexNo of the element that currently has focus.
It then loops trough the form to find the next indexNo and set focus to
that element.


/Robert


-----Ursprungligt meddelande-----
Fr=E5n: kriz buenaventura [mailto:vickriz@i...]
Skickat: den 29 oktober 2002 09:47
Till: JavaScript HowTo
=C4mne: [javascript_howto] Re: SV: Return Key/Enter Key Event Handler


this is the example code of my form..
<body onload=3D"show_time(), document.myform.surname.focus()"> <form
name=3D"myform">  <font size=3D"2">SurName</font><br>
  <input name=3D"surname" type=3D"text" 
onKeyPress=3D"EnterHandler(event)">
<font size=3D"2">FirstName</font><br>
  <input name=3D"firstname" type=3D"text">

now i want to have some function but my prob. is i dont know how to
built
my function using that onKeyPress or onKeyDown inside the body and also
how can i used the sample code u tellin me??

  <element onKeyDown=3D3D"if(event.keyCode =3D3D=3D3D 13) moveFocus()">

bytheway im just using IE5.5

thanks again robert your really big help.. more power...

---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogramm
e
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogramm
e
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogramm
e
r-20


  Return to Index