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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:00:44+00:00 2026-06-06T05:00:44+00:00

I have a simple login form and have jQuery validate replacing the field labels

  • 0

I have a simple login form and have jQuery validate replacing the field labels when there’s an error to display. The problem is that, once the error is cleared, the label disappears. I would like to find a way to revert back to the previous label’s content, or rebuild that label when the field is valid…

Here’s my code:

$(document).ready(function(){
    $("#login").validate({
        errorPlacement: function(error, element) {
            element.prev().replaceWith(error);
        },
        rules: {
            "email": {
                required: true,
                email:true,
            },
            "password": {
                required: true,
                minlength: 6
            }
        },
        messages: {
            email: {
                required: "Please enter your email address.",
                email: "Please enter a <u>valid</u> email address"
            },
            password: {
                required: "Please enter your password.",
                minlength: "Please enter a password with 6 characters or more."
            }
        },
    });
});

And the HTML:

<form name="login" id="login" method="post" action="authenticate.php">
<p>
    <label for="email">Email Address:</label>
    <input type="text" name="email" id="email" class="required email" />
</p>
<p>
    <label for="password">Password:</label>
    <input type="password" name="password" id="password" class="required" />
</p>
<p>
    <input type="submit" value="Log In" id="submit" />
</p>

In essence, when the user submits the form, if there’s no data in the Email field, then the label for email gets replaced with the error. But once it has valid input, I want to put back the original label.

Thanks in advance for any suggestions,

Z

  • 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-06T05:00:45+00:00Added an answer on June 6, 2026 at 5:00 am

    I actually worked out a compromise whereby, instead of replacing the previous label with the error label, I’m appending a span into that label using error.appendTo(element.prev()) and errorElement: “span”. Here’s the new code:

                $(document).ready(function(){
                $("#login").validate({
                    errorElement: "span",
                    errorPlacement: function(error, element) {
                        error.appendTo(element.prev());
                        //element.prev().replaceWith(error);
                    },
                    rules: {
                        "email": {
                            required: true,
                            email:true,
                        },
                        "password": {
                            required: true,
                            minlength: 6
                        }
                    },
                    messages: {
                        email: {
                            required: " is Required",
                            email: " is Improperly Formatted"
                        },
                        password: {
                            required: " is Required",
                            minlength: " is not Long Enough"
                        }
                    },
                });
            });
    

    It’s less than ideal, but at least when the span appears, the error code is where I want it to be, and when it disappears, the label remains intact. I just made it so the label and the error complete each other like sentences… Eg, “Email Address” ” is required.” or “Email Address” ” is not properly formatted.”

    Thanks to everybody that contributed here,

    Z

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

Sidebar

Related Questions

I have a simple login form that captures username/password with some simple Javascript (JQuery)
There are some HTML based games (ie bootleggers.us) that have a simple login form
I would like to have a simple login form (or any form for that
I have a simple form for a login, and I want to display the
I have a simple login form that has 2 text fields and a button.
i have a website that has a simple login form. the form posts to
I have simple login form in my website. In given requirements stands, that password
I have a simple password reset form that has a username field, and below
I have a login form using a UL and jQuery Validate. It looks fine
I have a jquery code that shakes a div when clicked. $(#error).click(function() { $(#box-login).show('shake',

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.