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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:25:39+00:00 2026-06-14T22:25:39+00:00

Objective : I’d like to display the focused field error message in a container.

  • 0

Objective: I’d like to display the focused field error message in a container.

What I’ve done so far:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <style type="text/css">
            label.pre {
                display:inline-block;
                width:60px;
            }
        </style>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"
        type="text/javascript"></script>
        <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"
        type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $("form").validate({
                    messages: {
                        name: "Please specify your name.",
                        email: {
                            required: "We need your email address to contact you.",
                            email: "Your email address must be in the format of name@domain.com."
                        },
                        url: "A valid URL, please.",
                        comment: "Please enter your comment."
                    },
                    showErrors: function (errorMap, errorList) {
                        if (errorList.length) {
                            $("span").html(errorList[0].message);
                        }
                    }
                });
            });
        </script>
    </head>
    <body>
<span></span>
        <form action="#">
            <div>
                <label class="pre" for="entry_0">Name *</label>
                <input type="text" class="required" name="name" id="entry_0">
            </div>
            <div>
                <label class="pre" for="entry_1">Email *</label>
                <input type="text" class="required email" name="email"
                id="entry_1">
            </div>
            <div>
                <label class="pre" for="entry_2">URL</label>
                <input type="text" class="url" name="url" id="entry_2">
            </div>
            <div>
                <textarea class="required" name="comment" id="entry_3" rows="7" cols="35"></textarea>
            </div>
            <div>
                <input type="submit" name="submit" value="Submit">
            </div>
        </form>
    </body>
</html>

Demo: http://jsfiddle.net/RainLover/32hje/

Problems:

  1. If you click the submit button, the container(span) shows the first
    error message, no matter which field was focused.
  2. Focusing on fields using the Tab key works well (except on the URL field), but focusing with a mouse doesn’t update the span HTML correctly.
  • 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-14T22:25:40+00:00Added an answer on June 14, 2026 at 10:25 pm

    Eureka! I just re-checked the validate options and realized I should have used errorPlacement instead of showErrors:

    <!DOCTYPE html>
    <html>
        <head>
            <title></title>
            <style type="text/css">
                label.pre {
                    display:inline-block;
                    width:60px;
                }
            </style>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"
            type="text/javascript"></script>
            <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"
            type="text/javascript"></script>
            <script type="text/javascript">
                $(document).ready(function () {
                    $("form").validate({
                        messages: {
                            name: "Please specify your name.",
                            email: {
                                required: "We need your email address to contact you.",
                                email: "Your email address must be in the format of name@domain.com."
                            },
                            url: "A valid URL, please.",
                            comment: "Please enter your comment."
                        },
                        errorPlacement: function (error, element) {
                            element.focus(function () {
                                $("span").html(error);
                            }).blur(function () {
                                $("span").html('');
                            });
                        }
                    });
                });
            </script>
        </head>
        <body>
            <form action="#">
    <span></span>
                <div>
                    <label class="pre" for="entry_0">Name *</label>
                    <input type="text" class="required" name="name" id="entry_0">
                </div>
                <div>
                    <label class="pre" for="entry_1">Email *</label>
                    <input type="text" class="required email" name="email"
                    id="entry_1">
                </div>
                <div>
                    <label class="pre" for="entry_2">URL</label>
                    <input type="text" class="url" name="url" id="entry_2">
                </div>
                <div>
                    <textarea class="required" name="comment" id="entry_3" rows="7" cols="35"></textarea>
                </div>
                <div>
                    <input type="submit" name="submit" value="Submit">
                </div>
            </form>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Objective-C uses a sophisticated message-passing system when one object calls a method on another
Objective : I'd like to store certain words inside database table as banned words
Objective: Be able to nest a resource, like records inside of users so that
In Objective-C, I'd like to force derived classes to implement a given interface without
Objective-C is a language like Smalltalk, but weakly, dynamically typed language. And I can
Objective: I would like to take a JSON String and pass it into JavaScript
Objective: I would like to pass Skins to an itemRenderer (which is a Button)
Objective-C, or Cocoa specifically, supports variadic arguments, like for example class the method on
Objective-C has no namespaces; it's much like C, everything is within one global namespace.
Objective: I would like to be able to list the available COM Ports on

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.