www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to Automatically Move the Curser from Input Text Box to the Next Input text box?

  1. #1
    Join Date
    Jul 2010
    Posts
    2

    How to Automatically Move the Curser from Input Text Box to the Next Input text box?

    I have taken a class on PHP and started making some math homework and drills for the tutoring I do. I have asked my kids for feedback and they are telling me that it is inconvenient to hit tab to go to the next text box (They have small arms/fingers..)

    I then thought of a brilliant idea.

    Letís say it was 12 divided by 3. If they wrote a 4 in the input area, the JavaScript would recognize the correct answer and automatically move to the next box. However, if they wrote a 3 in the box, the JavaScript wouldn't move over.

    This kills two birds with one stone. The inconvenience of hitting tab or clicking on the next box disappears, and they are forced to put in the correct answer.

    Ironically, I have learned PHP and skipped over JavaScript. Which code would I use to do this?

    Thank you so much.


    This is my first post on WebDeveloper.com, it looks pretty cool.

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    without your html and the quiz structure it is hard to imagine what's going on
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Jul 2010
    Posts
    2
    Figured it out, this isn't my script:
    Code:
    What is 6+7? <input type = "text" id = "Q1"  onkeyup = "goNext(this,2,13)">
    What is 2+9? <input type = "text" id = "Q2"  onkeyup = "goNext(this,3,11)">
    What is 8+9? <input type = "text" id = "Q3"  onkeyup = "goNext(this,4,17)">
    
    <script type = "text/javascript">
    function goNext(qu, nxt, ans) {
    nxt = "Q" + nxt;
    if (qu.value == ans) {
    document.getElementById(nxt).focus();
    }
    }
    </script>

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,648
    http://www.padonak.aalux.ee/webdevel..._math_quiz.htm try this may be your kids will love it aswell ;-)
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles