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

  • Home
  • SEARCH
  • 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 3790984
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:23:59+00:00 2026-05-19T12:23:59+00:00

I have a web page with 3 web forms, where the first two expect

  • 0

I have a web page with 3 web forms, where the first two expect digital input and the last one may not be empty.

A web form showing three text fields, two of them containing invalid inputs

Here is the reduced and ready-to-run test case:

<html>
<head>
<style>
.invalid {
        border: 2px solid #FF0000;
        background-color: #FFCCCC;
}
</style>
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript">
$(function() {
        //$('body').click(....)
        $('#cl_txt, #mks_txt, #comment_txt').blur(function() {
           $('#cl_txt, #mks_txt, #comment_txt').removeClass('invalid');
        });

        $('#mks_btn').click(function(e) {
            if (! $('#mks_txt').val().match(/^[0-9]{6,}$/i)) {
                $('#mks_txt').addClass('invalid');
                e.preventDefault();
            }
        });
        $('#cl_btn').click(function(e) {
            if (! $('#cl_txt').val().match(/^[0-9]{6,}$/i)) {
                $('#cl_txt').addClass('invalid');
                e.preventDefault();
            }
        });
        $('#comment_btn').click(function(e) {
            if ($('#comment_txt').val().length < 2) {
                 $('#comment_txt').addClass('invalid');
                 e.preventDefault();
            }
        });
});
</script>
</head>
<body>
<table border=1>
<form><tr><th>MKS</th><td>
<input name="toggle_mks" id="mks_txt" type="text" size="10">
<input type="submit" id="mks_btn" value="Add MKS" class="toggle">
</td></tr>
<form><tr><th>CL</th><td>
<input name="toggle_cl" id="cl_txt" type="text" size="10">
<input type="submit" id="cl_btn" value="Add CL" class="toggle">
</td></tr></form>
<form><tr><th>Comments</th><td>
<textarea name="comment" id="comment_txt" rows="4" cols="40">
</textarea>
<input type="submit" id="comment_btn" value="Add comment" class="toggle">
</td></tr></form>
</table>
</body>
</html>

When invalid text has been entered and the corresponding submit button clicked, then I add the .invalid class to that text field or text area to make it appear red.

My problem is in handling situations, where the user changes her mind and decides not to submit that web form again. Instead she clicks into another web form or maybe just clicks somewhere in the web page.

In that case I would like the red .invalid class to be removed from the text elements #cl_txt, #mks_txt and #comment_txt again. But I don’t know how to arrange it. I’ve tried setting $(‘#cl_txt, #mks_txt, #comment_txt’).blur(….) but it never works consistently. I’ve tried $(‘body’).click(….) instead, but then form validation seems to break, the text fields are never painted red.

Any help please?

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

    Try to use jQuery outside events plugin. Also, see the demo.
    The main idea is that you delegate to element a clickoutside (or even dblclickoutside) event and specify what should happen when it fires.

    Hope that will help.

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

Sidebar

Related Questions

I have the following problem. I got two forms on my web page. On
I have two forms on one page: a results form and a search form.
I have web forms page that has 2 controls. A gridview and an associated
I have a web page where i have 2 forms when i click the
I have an ASP.NET Web Forms web site. It has a page inside of
I have an ASP.NET web application that takes user input across several forms. Sort
I am building a web app with jquery mobile. On one page I have
We have two apache/php web servers load balanced with squid page caching proxy. The
I have a form where two fields on the first page of the form
Situation: you have a web page with a form that has a first name

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.