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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:09:57+00:00 2026-05-27T06:09:57+00:00

I am trying to validate three fields in my form. The form is a

  • 0

I am trying to validate three fields in my form. The form is a simple contact me form and the JavaScript. Below is the javascript code for the validation:

 <script type="text/javascript"><!--
function validateForm() {
 with (document.contact-form) {
 var alertMsg = "The following REQUIRED fields\nhave been left empty:\n";
 if (name.value == "") alertMsg += "\nNAME IS REQUIRED";
 if (email.value == "") alertMsg += "\nEMAIL IS REQUIRED";
 if (phone.value == "") alertMsg += "\nPHONE IS REQUIRED";
 if (alertMsg != "The following REQUIRED fields\nhave been left empty:\n") {
 alert(alertMsg);
 return false;
 } else {
return true;
} } }

 // --></script>

And My HTML Code For the Form is:

  <form id="contact-form" name="contact-form" action="form.php" method="post" 
    onsubmit="return validateForm()">
<input id="name" type="name" name="name" value="NAME"  
     onfocus="if (this.value=='NAME') this.value='';" onblur="if (this.value=='') 
     this.value='NAME';"/><br />
<input id="email" type="email" name="email" value="EMAIL" onfocus="if     
    (this.value=='EMAIL') this.value='';" onblur="if (this.value=='') 
    this.value='EMAIL';" /><br />
<input id="phone" type="text" name="phone" value="PHONE" class="phone" onfocus="if 
    (this.value=='PHONE') this.value='';" onblur="if (this.value=='')   
     this.value='PHONE';" /><br />
<input type="text" name="event-location" value="EVENT LOCATION" onfocus="if  
    (this.value=='EVENT LOCATION') this.value='';" onblur="if (this.value=='')  
    this.value='EVENT LOCATION';" /><br />
<input type="text" name="event-date" value="EVENT DATE" onfocus="if  
    (this.value=='EVENT DATE') this.value='';" onblur="if (this.value=='')  
     this.value='EVENT DATE';" /><br />
<input type="text" name="event-time" value="EVENT TIME" onfocus="if  
    (this.value=='EVENT TIME') this.value='';" onblur="if (this.value=='')  
    this.value='EVENT TIME';" /><br />
<input type="text" name="message" value="MESSAGE" class="message" onfocus="if  
    (this.value=='MESSAGE') this.value='';" onblur="if (this.value=='')  
     this.value='MESSAGE';" /><br />
<input type="submit" name="send" value="SEND" />
</form>

Any Help would be highly appreciated.

Thanks

  • 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-27T06:09:58+00:00Added an answer on May 27, 2026 at 6:09 am

    Try this

    <script type="text/javascript"><!--
     function validateForm() {
      var mytable = document.getElementById('contact-form');
      with (mytable) {
        var alertMsg = "The following REQUIRED fields\nhave been left empty:\n";
        if (name.value == "" || name.value == "NAME") alertMsg += "\nNAME IS REQUIRED";
        if (email.value == "" || email.value == "EMAIL") alertMsg += "\nEMAIL IS REQUIRED";
        if (phone.value == "" || phone.value == "PHONE") alertMsg += "\nPHONE IS REQUIRED";
        if (alertMsg != "The following REQUIRED fields\nhave been left empty:\n") {
          alert(alertMsg);
          return false;
        } else {
          return true;
        }  } }
    // --></script>
    

    OR a little more direct

    <script type="text/javascript"><!--
     function validateForm() {
      var mytable = document.getElementById('contact-form');
      var alertMsg = "The following REQUIRED fields\nhave been left empty:\n";
      if (document.getElementById('name').value == "") alertMsg += "\nNAME IS REQUIRED";
      if (document.getElementById('email').value == "") alertMsg += "\nEMAIL IS REQUIRED";
      if (document.getElementById('phone').value == "") alertMsg += "\nPHONE IS REQUIRED";
      if (alertMsg != "The following REQUIRED fields\nhave been left empty:\n") {
         alert(alertMsg);
         return false;
      } else {
         return true;
      } }
    // --></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form with fields that I am trying to validate using
I am trying to validate a form in that if there is no text
I'm trying to validate a form by checking the required fields with a jQuery
I'm trying to write a simple form. The form basically need to validate 2
Hey there, I'm trying to validate a form with Zend_Validate and Zend_Form. My element:
I am currently trying to validate a form server side, the way it works
I was trying to validate an XML signature. The validation according to this tutorial
I have a PHP form that needs some very simple validation on submit. I'd
I'm trying to validate my inputs with jQuery before a form is sent. This
I am trying to validate a phone number which is contained over two fields.

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.