• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Code works, but HOW?

<SCRIPT TYPE="text/javascript">
<!--
var downStrokeField;
function autojump(fieldName,nextFieldName,fakeMaxLength)
{
var myForm=document.forms[document.forms.length - 1];
var myField=myForm.elements[fieldName];
myField.nextField=myForm.elements[nextFieldName];

if (myField.maxLength == null)
   myField.maxLength=fakeMaxLength;

myField.onkeydown=autojump_keyDown;
myField.onkeyup=autojump_keyUp;
}

function autojump_keyDown()
{
this.beforeLength=this.value.length;
downStrokeField=this;
}

function autojump_keyUp()
{
if (
   (this == downStrokeField) && 
   (this.value.length > this.beforeLength) && 
   (this.value.length >= this.maxLength)
   )
   this.nextField.focus();
downStrokeField=null;
}
//-->
</SCRIPT>

</HEAD>
<BODY>
<P>Place content here.</P>
<FORM ACTION="../cgi-bin/mycgi.pl" METHOD=POST>

SSN:
<INPUT TYPE=TEXT NAME="ssn_1" MAXLENGTH=3 SIZE=3> -
<INPUT TYPE=TEXT NAME="ssn_2" MAXLENGTH=2 SIZE=2> -
<INPUT TYPE=TEXT NAME="ssn_3" MAXLENGTH=4 SIZE=4><BR>

email: <INPUT TYPE=TEXT NAME="email"><BR>

</FORM>
<SCRIPT TYPE="text/javascript">
<!--
autojump('ssn_1', 'ssn_2', 3);
autojump('ssn_2', 'ssn_3', 2);
autojump('ssn_3', 'email', 4);
//-->
</SCRIPT>

</BODY>
</HTML>

There are no events on the input boxes? When, or how, is function autojump being called?
I could understand this
<INPUT TYPE=TEXT NAME="ssn_2" MAXLENGTH=2 SIZE=2 onkeypress"(autojump...)">
0
Paullkha
Asked:
Paullkha
  • 2
  • 2
  • 2
2 Solutions
 
knightEknightCommented:
here is where the event handlers are being set:

myField.onkeydown=autojump_keyDown;
myField.onkeyup=autojump_keyUp;
0
 
dakydCommented:
This section:

<SCRIPT TYPE="text/javascript">
<!--
autojump('ssn_1', 'ssn_2', 3);
autojump('ssn_2', 'ssn_3', 2);
autojump('ssn_3', 'email', 4);
//-->
</SCRIPT>

assigns the event handlers for the ssn_1, ssn_2, and ssn_3 fields.  The autojump function assigns onkeydown and onkeyup handlers to the field whose name is the first parameter.  So, for example,autojump('ssn_1', 'ssn_2', 3) assigns the onkeydown and onkeyup for ssn_1. Hope that helps.
0
 
dakydCommented:
oops, sorry knightEknight, looks like you were quicker on the trigger.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
knightEknightCommented:
we are both right :)
0
 
PaullkhaAuthor Commented:
Damn, see it now, kewl thx
0
 
PaullkhaAuthor Commented:
In other words, the code is their, but not within view source. (Like C++ handlers)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now