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 7559981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:46:45+00:00 2026-05-30T12:46:45+00:00

Four text boxes are in a JSP page. After entering first text box, when

  • 0

Four text boxes are in a JSP page. After entering first text box, when I press Tab, the focus moves to the second text box. Similarly the focus will be on 3rd and 4th text box after pressing Tab repeatedly.

<input type="text" id="textbox1"/>
<input type="text" id="textbox2"/>
<input type="text" id="textbox3"/>
<input type="text" id="textbox4"/>

If I move from the first to the third text box without filling the second text box, then I want to have an alert come as “2nd text box cannot be empty”. Similarly after entering data on first, second if I am moving to the fourth text box without filling the third text box, then I want an alert as “3rd text box cannot be empty”. And after the alert the focus must be on that empty text box again, the focus must not move further. How can I do this?

  • 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-05-30T12:46:46+00:00Added an answer on May 30, 2026 at 12:46 pm

    You’ve tagged the question with jQuery so I’ll give you a jQuery solution. You may want to make the selector a bit more specific, depending on your HTML:

    $("input").blur(function() {
        if(!this.value) {
            alert("Text box " + ($(this).index() + 1) + " cannot be empty.");
            this.focus(); //Keep focus on this input
        }
    });
    

    This binds an event handler to the blur event of the elements (which fires when the field loses focus, be it through pressing tab, clicking elsewhere or any other method of changing focus). The event handler checks whether the field has a value, and if not it alerts a message, using the jQuery index method to get the index of the element relative to its siblings.

    Here’s a working example.

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

Sidebar

Related Questions

I have four input boxes. If the user fills the first box and clicks
I have two web pages: one consists of four asp.net text boxes and one
I currently have a page with four list boxes on it and imagine a
I have four text boxes all with similar code. Each one on hover fades
I am working on a WinForms application. There are four text boxes and one
I use four asp.net text boxes to capture data. I need to allow data
I created a simple Converter to concatenate the text of four TextBoxes in my
I've created a simple Project model with four attributes: Project name:string description:text complete:boolean user_id:integer
I have a gridview which contains a text box as a template field.the grid
I have this xml that contains four text messages and i have converted that

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.