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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:14:42+00:00 2026-06-17T02:14:42+00:00

i am new to jquery and i start learning jquery fundamental. i make script

  • 0

i am new to jquery and i start learning jquery fundamental. i make script of jquery for registration form. it’s works fine while on submit a form with single or both field empty, query show error messages but if i again fill the empty field then also it show the same error message and on reload message stop showing.

<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
  <style>
  c { color:red; margin:4px; }
  b { color:blue; }
  </style>
  <script src="jquery-latest.js"></script>
  <script src="jquery.js"></script>
</head>
<body>

<h1>Registration Form:</h1>

<form id="form1">

<div>First Name<input type="text" name="fname" id="fname"><span></span></div>
<div>Last Name<input type="text" name="lname" id="lname"><span></span></div>
<div><input type="submit" value="submit" ></div>

</form> 

<script>

$(document).ready(function(){

    $("#form1").submit(function(){
        var $spans = $("span");

        if ($('#fname').val()=="") {    
        $spans.eq(0).html("<c>Please enter your Firstname</c>");
        }       
        if ($('#lname').val()==""){
        $spans.eq(1).html("<c>Please enter your Lastname</c>");

        }return false;

    });
});
</script>
  • 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-17T02:14:43+00:00Added an answer on June 17, 2026 at 2:14 am

    That’s because you do not remove the text content when input is no empty. Note that you should not laod jQuery twice and c is not a valid tag.

    var $spans = $("span"); 
    $("#form1").submit(function(){ 
        $spans.eq(0).html( $('#fname').val() == "" ? "Please enter your Firstname" : "");
        $spans.eq(1).html( $('#lname').val() == "" ? "Please enter your Lastname" : "");
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Jquery and trying to start learning the new tool. What
Start learning Ajax (and jQuery), I encounter the issue with post form data, which
First off, the jQuery datepicker works fine with classes when doing a fresh page
I'll start by saying I'm fairly new to jQuery. For the most part, I've
I'm new to jquery so I have no idea where to start. I want
I'll start off by saying I'm new to jQuery but I am really enjoying
I'm fairly new to jQuery and I'm using the script below. Basically it uses
Let me start by saying I am VERY new to jQuery or any JavaScript
New to Ajax calls. Need some pointers to start my learning but want to
I am new to jquery (and all programming), so I am trying to start

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.