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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:30:32+00:00 2026-05-26T07:30:32+00:00

I put the form validation with span in my previous example cannot display all

  • 0

I put the form validation with span in my previous example
cannot display all warning message in form validation with span

but when I use more than 1 validation on a single field then I face problem to show in span like

 var x=document.forms["reg"]["email"].value;
  var atpos=x.indexOf("@");
   var dotpos=x.lastIndexOf(".");
 if(x ==null || x=="")
 {
   document.getElementById("error2").innerHTML = "enter Email"

   $var=false;
 }
 if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
 {
   document.getElementById("error3").innerHTML = "enter correct Email"
   $var=false;
 }

and in form field are

                <td>Email:</td>
                <td><input type="text" name="email" id="email"    /><span id="email_error" style="color:red;"></span>
                <span id="error2" style="color:red;"></span>
                <span id="error3" style="color:red;"></span></td>

If I use this code and leave the field blank then it shows both errors like
“ENTER EMAIL ENTER CORRECT EMAIL”. How can I fix this?

  • 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-26T07:30:32+00:00Added an answer on May 26, 2026 at 7:30 am

    because your script is calling as soon as the page loads and there are not any values supplyed sp it runs as expected, you could place a function around it and call from for example, form onsubmit, or a inline event handler such as onblur on the email input element.

    i dont know what $var is for but it is undeclared

    try this

    <input type="text" name="email" id="email"  onblur="checkEmailField()"/>
    

    and the following function, this wont show “enter email” unless the user focuses on the email field then moves away from the field without entering anything.

    function checkEmailField(){
    
    
     var x=document.forms["reg"]["email"].value;
      var atpos=x.indexOf("@");
       var dotpos=x.lastIndexOf(".");
    if(x ==null || x=="" )
    {
      document.getElementById("error2").innerHTML = "enter Email"
    document.getElementById("error3").innerHTML = "";
       $var=false;
    }else 
    
     if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length &&  x != "" && x!=null)
     {
     document.getElementById("error2").innerHTML = "";
    document.getElementById("error3").innerHTML = "enter correct Email"
    
     $var=false;
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to put together some Javascript form validation to check that all fields
I've a form with an inline validation message in a span. <span id=EndTimeErrors> <label
Where do you put user input validation in a web form application? View: JavaScript
Rep steps: create example .NET form application put a TextBox on the form wire
Can you give me an example on how to put my application form in
I use the JQuery Validation plugin to validate a form ( http://docs.jquery.com/Plugins/Validation/ ) For
There are two places to put form validation when developing with rails - Model
I could use some guidance in how to proceed on form validation in CodeIgniter.
How do i (using jquery validation) put all the messages in a div tag
I use the config.php to store all the form_validation rules...But I would like to

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.