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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:44:39+00:00 2026-06-09T06:44:39+00:00

I Have done a login form validation using jquery, But Thing is error message

  • 0

I Have done a login form validation using jquery, But Thing is error message come inside the text box. can any one help me to put the validation message near the input field. For More information pl Check that Site.

http://192.168.109.1:8084/AsiaHospital/login.jsp



 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <%@include file="header.jsp"%>
    <head>
        <style type="text/css">
            body, input, textarea {
                font-size:12px;
                line-height:18px;
                font-family:Verdana, Geneva, sans-serif;
            }


            #error {
                color:#dd4466;
                font-size:10px;
                display:none;
            }
            .needsfilled {
                background:#958585;
                color:white;
            }
        </style>
        <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="javascript/loginvalidation.js"></script>

    </head>
    <div id="templatemo_content_right">
        <h1>Login Form</h1>
        <center>
            <form action="LoginServlet" method="POST" id="theform" name="theform">
                <table cellspacing="20" cellpading="10">
                    <tr>
                        <td>UserName:</td>
                        <td><input type="text" name="userName" id="userName"/></td>
                    </tr>
                    <tr>
                        <td>Password:</td>
                        <td><input type="password" name="password" id="password"/></td>
                    </tr>
                    <tr>
                        <td><input type="submit" value="Login"/></td>
                    </tr>


                </table>



            </form>
        </center>

        <div class="cleaner_with_height">&nbsp;</div>

    </div> <!-- end of content right -->
    <%@include file="footer.jsp" %>
</html>

    /* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$(document).ready(function(){
    // Place ID's of all required fields here.
    required = ["userName", "password"];

    // If using an ID other than #email or #error then replace it here
    email = $("#email");
    errornotice = $("#error");
    // The text to show up within a field when it is incorrect
    emptyerror = "Please fill out this field.";
    emailerror = "Please enter a valid e-mail.";

    $("#theform").submit(function(){    
        //Validate required fields
        for (i=0;i<required.length;i++) {
            var input = $('#'+required[i]);
            if ((input.val() == "") || (input.val() == emptyerror)) {
                input.addClass("needsfilled");
                input.val(emptyerror);
                errornotice.fadeIn(750);
            } else {
                input.removeClass("needsfilled");
            }
        }
        // Validate the e-mail.

        //if any inputs on the page have the class 'needsfilled' the form will not submit
        if ($(":input").hasClass("needsfilled")) {
            return false;
        } else {
            errornotice.hide();
            return true;
        }
    });

    // Clears any fields in the form when the user clicks on them
    $(":input").focus(function(){       
       if ($(this).hasClass("needsfilled") ) {
            $(this).val("");
            $(this).removeClass("needsfilled");
       }
    });
});
  • 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-09T06:44:41+00:00Added an answer on June 9, 2026 at 6:44 am

    Try changing this line,

    input.val(emptyerror);
    

    to

    input.after('<span>'+emptyerror+'</span>');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to place a login inline-form in a twitter navbar. I have done
on my web site I want to have login/registration form in modal window done
The thought of having input validation on my login form had come across my
I have created a login form. It works fine, but it goes back to
Hi i have developed a login form (username,password and submit button) using a MySQL
no title that fits this bug but this how it goes, i have form
I am under: Rails 3.0.9 Devise 1.4.7 jquery-ujs What have I done?... 1) I
I have this login form which uses AJAX to query a database for checking
I have used a tutorial here: http://www.phpeasystep.com/phptu/26.html to create a login form for my
I'm trying to make a login form for my kohana2 app using ORM example

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.