Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7935125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:49:47+00:00 2026-06-03T21:49:47+00:00

I am trying to automatically jump to the second line after a certain number

  • 0

I am trying to automatically jump to the second line after a certain number of characters. I am using the keypress function in jquery to do so. Here is my code:

<html>
<head>
    <script type="text/javascript" src="http://inet.website-name.com/jquery/jquery-1.7.min.js"></script>
</head>
<body>
    <input id="input1"></input>
    <br />
    <input id="input2"></input>
    <script type="text/javascript">
        $('#input1').keypress(function (e) {
            var tval = $('#input1').val();
            if (tval.length >= 5 && e.which !== 0 && e.charCode !== 0) {
                $('#input2').focus();
            }
        })      
    </script>
</body>
</html>

The problem I am encountering is when this is run in chrome the 6th character is typed in the first box followed by the focus changing to the second box. When this is run in Internet Explorer, the focus is first changed to the second box and then the 6th character is typed. I need it to have the same behavior in both browsers.

I tried using the keydown event and that worked in terms of changing the focus consistently but the focus would change even if I used the backspace, arrow keys or any other special key.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:49:49+00:00Added an answer on June 3, 2026 at 9:49 pm

    You could switch it to a keyup event and it will work, though you will not be able to use the e.charCode check (is it there for a reason?). Also note that the >= 5 was changed to a > 5

        $('#input1').keyup(function (e) {
             var c = String.fromCharCode(e.keyCode);
             var isWordcharacter = c.match(/\w/);//matches a-z, A-Z, 0-9, and _
             var tval = $('#input1').val();
             if (tval.length > 5 && e.which !== 0 && isWordcharacter) {
                 $('#input2').focus();
             }
        });
    

    Fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to automatically generate a line chart using VBA and Excel where each
Using jQuery, I am trying to automatically replace every... www.mywebsite.com/blog/category/categoryname by www.mywebsite.com/blog/#categoryname ...in my
I'm trying to understand why when I automatically jump to a 2nd view (using
I am trying to automatically send SMS message to a certain number when the
I'm trying to automatically compress both CSS and JS using maven and this plugin
I'm trying to login automatically in a website using Perl with WWW::Mechanize . What
I'm trying to make a script that automatically starts uploading after the data has
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying to replace some div text automatically using the .html command in
I am trying to move the following function listView_SelectionChanged away from code-behind and handle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.