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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:55:24+00:00 2026-05-21T06:55:24+00:00

Using jquery to validate that there is text in a text box. When I

  • 0

Using jquery to validate that there is text in a text box. When I first start my page and leave the text box null then my background image in a TD element two cells from the text box shows a red box and after I click a button. If I enter text then click my button then a green check icon is shown directly next to the text box. This is all good.

However, when I remove any text in the text box click my button I don’t get a red box in my TD element anymore as I did the first time that I started my page.

Thanks for any assistance.

CSS:

.Error
  {
     background-image: url('../Images/Red-Error-Box.png');
     background-repeat: no-repeat;
     background-position: center;
  }
.Empty
  {
     background: white;
     height: 15px;
     width: 237px;
  }

JavaScript:

function firstNameError() {
    $('#FirstNameErrorMSG').addClass('Error');
    $('#FirstNameErrorMSG').text('Please enter a first name');
    $('#FirstNameErrorMSG').show();
    $('#imgFirstName').attr('src', '../Images/Red-Error-Icon.png');
    $('#imgFirstName').show();
}

function firstNameValid() {
    $('#FirstNameErrorMSG').addClass('Empty');
    $('#FirstNameErrorMSG').text('');
    $('#FirstNameErrorMSG').show();
    $('#imgFirstName').attr('src', '../Images/Green-Check-Icon.png');
    $('#imgFirstName').show();
}

//null first name.
if (!$("#tbFirstName").val()) {
     firstNameError();
}

//not null first name.
if ($("#tbFirstName").val()) {
    firstNameValid();
}

HTML:

<td class="style46">
    <img id="imgFirstName" alt="" class="None">
</td>
<td id="FirstNameErrorMSG" runat="server"></td>
  • 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-21T06:55:25+00:00Added an answer on May 21, 2026 at 6:55 am

    You have these two validator functions in the global scope:

     //null first name.
    if (!$("#tbFirstName").val()) {
           firstNameError();
    }
    
    //not null first name.
    if ($("#tbFirstName").val()) {
              firstNameValid();
          }
    

    Which means when you alter the textbox your not telling the jQuery to do anything. I suspect you want onBlur function:

    $(function() {
    
         firstNameError(); //Check on dom ready
         firstNameValid(); //Check on dom ready
    
    $("#tbFirstName").bind('blur','focus',function() {
        myValidator();
    });
    
        function myValidator() {
              //null first name.
              if (!$("#tbFirstName").val()) {
                   firstNameError();
              }
                else if ($("#tbFirstName").val()) {
                  firstNameValid();
              }
         }
    });
    
        function firstNameError() {
            $('#FirstNameErrorMSG').addClass('Error');
            $('#FirstNameErrorMSG').text('Please enter a first name');
            $('#FirstNameErrorMSG').show();
            $('#imgFirstName').attr('src', '../Images/Red-Error-Icon.png');
            $('#imgFirstName').show();
          }
    
        function firstNameValid() {
            $('#FirstNameErrorMSG').addClass('Empty');
            $('#FirstNameErrorMSG').text('');
            $('#FirstNameErrorMSG').show();
            $('#imgFirstName').attr('src', '../Images/Green-Check-Icon.png');
            $('#imgFirstName').show();
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using jquery how do I focus the first element (edit field, text area, dropdown
Using jQuery, is there a way to select all tag that reference a specific
Fields on the site are validated using JQuery Validate: http://bassistance.de/jquery-plugins/jquery-plugin-validation/ When there's one e-mail,
I'm using jQuery validate on a form I am building and it is working
Using the jQuery Validation plugin and AJAX, how can I validate the contents of
Using jQuery, how do you check if there is an option selected in a
Using jQuery, how do I delete all rows in a table except the first?
I am using the jQuery Validation plugin and have an issue validating items that
I am using asp.net mvc 2.0 and jquery validate 1.7 ( http://bassistance.de/jquery-plugins/jquery-plugin-validation/ ) What
I'm using JQuery Validation to validate a particular textbox in my form. The textbox

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.