Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: SV: Return Key/Enter Key Event Handler part II


Message #1 by "Robert Nyman" <robert.nyman@c...> on Tue, 29 Oct 2002 14:37:56 +0100
Hi Robert How are you??

I am trying to run the code you sent to kriz but am getting this error:

"Object does not support this method or property"

This happens on line 7 when I press the enter key:

var intNewIndexFocus = parseInt(this.getAttribute("indexNo"), 10) + 1;

Please could you clarify to me what I am doing wrong. Also, I am not able 
to write any text on the input box..any ideas why??

This is the code I am using:

<html>
   <head>
	<script language="Javascript">
		  function EnterHandler()
		  {
			if(event.keyCode == 13)
			{
				var intNewIndexFocus = parseInt
(this.getAttribute("indexNo"), 10) + 1;
				var arrInputFields = 
document.getElementById("myform").getElementsByTagName("input");
				for(var i=0; i<arrInputFields.length; i++)
				{
					var oInput = arrInputFields[i];
					if(oInput.getAttribute("type") 
== "text" && parseInt(oInput.getAttribute("indexNo"), 10) == 
intNewIndexFocus)
					{
						oInput.focus();
					}
				}
			}
		}
	</script>
   </head>
   <body>
   

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

   </body>
</html>





> > the task of function should be, once i press the enter key it would 
focus 
m> > y cursor the the next input text and the submit button should 
inactive 
u> > ntil when i reach the last input text next to it.

> 
A> re you using the web interface for reading the e-mails?
B> ecause the syntax seems to have gotten screwed up in that...

> In all if statements, it should be two == in a row, not just one...
T> his might be what causes you the error.

> The easiest idea regarding your form submitting might be to add the
o> nSubmit event handler to the FORM tag, and then :

> <form onSubmit="return false;">

> 
I>  know that the code will work, so you might need to do some adapting of
t> he code to your own situation, and some error checking...

> 
/> Robert


  Return to Index