Solved

Code works, but HOW?

Posted on 2004-11-01
171 Views
Last Modified: 2008-02-01
<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
Question by:Paullkha
    6 Comments
     
    LVL 33

    Assisted Solution

    by:knightEknight
    here is where the event handlers are being set:

    myField.onkeydown=autojump_keyDown;
    myField.onkeyup=autojump_keyUp;
    0
     
    LVL 19

    Accepted Solution

    by:
    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
     
    LVL 19

    Expert Comment

    by:dakyd
    oops, sorry knightEknight, looks like you were quicker on the trigger.
    0
     
    LVL 33

    Expert Comment

    by:knightEknight
    we are both right :)
    0
     
    LVL 4

    Author Comment

    by:Paullkha
    Damn, see it now, kewl thx
    0
     
    LVL 4

    Author Comment

    by:Paullkha
    In other words, the code is their, but not within view source. (Like C++ handlers)
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now