[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Auto Jump in JavaScript

I think this may be an easy question, but I'm not fluent enough in JavaScript to figure it out myself.

The 3 boxes are able to jump to one another, but they won't let me jump back when I use "SHIFT-TAB".  Is it possible?  Here's the script:

</script>
function jump()
{
if ( document.form1.phone1.value.length == 3 )
{
document.form1.phone2.focus();
}
if ( document.form1.phone2.value.length == 3 )
{
document.form1.phone3.focus();
}
if (document.form1.phone3.value.length == 4)
{
document.form1.email.focus();
}
}

</script>

Open in new window


And then a snippet of code from the form:
<TR><TD>
*Home Phone:
</TD><TD>
<INPUT tabIndex="5" size="3" maxlength="3" id="phone1" name="phone1" value="" onkeyup="jump()">
<INPUT tabIndex="6" size="3" maxlength="3" id="phone2" name="phone2" value="" onkeyup="jump()">
<INPUT tabIndex="7" size="4" maxlength="4" id="phone3" name="phone3" value="" onkeyup="jump()">
</TD></TR>

Open in new window


Thanks in advance!
0
happysunny
Asked:
happysunny
  • 3
  • 2
1 Solution
 
cmalakarCommented:
try with this..
function jump()
{
if(event.keyCode == 9 || event.keyCode == 16){
return true;
}

if ( document.form1.phone1.value.length == 3 )
{
document.form1.phone2.focus();
}
if ( document.form1.phone2.value.length == 3 )
{
document.form1.phone3.focus();
}
if (document.form1.phone3.value.length == 4)
{
document.form1.email.focus();
}
}

Open in new window

0
 
happysunnyAuthor Commented:
That made it possible to go back, but it isn't automatically moving forward.
0
 
cmalakarCommented:
>> but it isn't automatically moving forward.

What do you mean by that ?
0
 
happysunnyAuthor Commented:
The code above will accept 3 characters, then another 3, then 4, all to complete a phone number.  Then it will automatically jump to the email.  When I try to go back to change the phone number using SHIFT TAB in Firefox, it won't automatically go back.  I have to hold down the shift key and force it, otherwise it will stay in the email input box.  And though I know this, not everyone will know to do this.
0
 
happysunnyAuthor Commented:
I finally realized this was an impossible question.  I don't think there is anyway this can be done.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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