Jump to content

move between text boxes


ngreenwood6

Recommended Posts

I have created a form on my site. I want the form to move to the next text  box automatically  after the user fills in the first one. please let me know if you have any suggestions. thanks in advance.

 

What is "full"? If they are typical text fields and you have a static number of characters required by the field, you could have a JavaScript function like this to help:

function jumpField(ele, max_chars, new_field_id)
{
  if (ele.value.length >= max_chars)
  {
    document.getElementById(new_field_id);
  }
}

 

Then, you would add something like this to your input declaration:

<input type="text" name="my_field" id="my-field" onkeyup="jumpField(this, 5, 'my-other-field');" maxlength="5" />
<input type="text" name="my_other_field" id="my-other-field" maxlength="5" />

 

Also, I'm moving this to the JavaScript forums since this is a client side question...

Link to comment
Share on other sites

Here's a simple example, easily improved upon.

 

(<input type="text" name="phone1" id="phone1" size="3" maxlength="3" onkeyup="if(this.value.length()==this.getAttribute('maxlength')){document.getElementById('phone2').focus();}">) - 
<input type="text" name="phone2" id="phone2" size="4" maxlength="4" onkeyup="if(this.value.length()==this.getAttribute('maxlength')){document.getElementById('phone3').focus();}"> - 
<input type="text" name="phone3" id="phone3" size="4" maxlength="4">

 

It's quite basic, all inside textboxes, and could be improved upon by separating it into a function which checks it's length and returns true/false, etc...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.