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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:19:09+00:00 2026-05-21T18:19:09+00:00

Okay, so I have the form set to my PHP page. I also have

  • 0

Okay, so I have the form set to my PHP page. I also have the submit button onsubmit set to my validation javascript. What happens is that it goes directly to my php page and does not validate the input? What am I missing? Do I have this set up right? If I remove the php file from the form the javascript validate works fine. It is trying to use the php and javascript together that drives me insane.

      <html xmlns="http://www.w3.org/1999/xhtml" >
      <head>
      <link rel="stylesheet" type="text/css" href="styles/styles_Final.css"/> 
      <title>contact.html</title>   
         <script type= "text/javascript" src = "scripts/validator.js"></script> 

      </head> 

      <div id="right-cont">

        <form name = "contact_Us" action="http://nova.umuc.edu/cgi-bin/cgiwrap/ct386a28/eContact.php" method = "post"> 

            <div id="style2">
                <p>Please enter contact information below:</p>                                 
            </div>

            <div class="style7">
                <label>First Name: </label>
                &nbsp;<br /><input type="text" name = "firstName" id="firstName" tabindex="1" 
                    style="width: 176px" />
            </div>  

            <div class="style7">
                <label>Middle Name: </label>
                &nbsp;<br /><input type="text" name = "middleName" id ="middleName" tabindex="2" 
                    style="width: 176px" />
            </div>

            <div class="style7">
                <label>Last Name: </label>
                &nbsp;<br /><input type="text" name = "lastName" id ="lastName" tabindex="3" 
                    style="width: 176px" />
            </div>         

              <div class="style8">
                <label>Questions and/or comments: </label>
                &nbsp;<br /> <textarea name = "comment" id = "comment" rows = "10" cols = "60"></textarea>
              </div>             

          <div class =" buttons">
            <input type="submit" value="SUBMIT" onclick = "return validate()"/><input type="reset" value="CLEAR"/> <br />                
          </div> 
          </div>              
       </form>
   </div>  

**************JAVASCRIPT**************************

   function validate() {
   //create references
   var fName;
   var mName;
   var lName;
   var email;
   var phone;

   fName = document.getElementById('firstName').value;  
       mName = document.getElementById('middleName').value;  
       lName = document.getElementById('lastName').value;  
       email = document.getElementById('email').value;  

       //validate the phone number     
       phone = document.getElementById('phone').value; 
       var boolean = isPhoneNumber(phone);

       if (!boolean)
       {
           alert("Please enter valid phone number format: ddd-ddd-dddd.");
           return false;
       }  

       //validate the email address
       email_Val()

       //validate the first name
       var fN=document.forms["contact_Us"]["firstName"].value
       if (fN==null || fN=="")
       {
          alert("Please fill in first name.");
          return false;
       }

       //validate the last name
       var lN=document.forms["contact_Us"]["lastName"].value
       if (lN==null || lN=="")
       {
       alert("Please fill in last name.");
       return false;
       }


   }

   function isPhoneNumber(phone)
   {
       var str = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
       return str.test(phone);
   }

   function email_Val()
   {
       var eM=document.forms["contact_Us"]["email"].value
       var x=eM.indexOf("@");
       var y=eM.lastIndexOf(".");
       if (x<1 || y<x+2 || y+2>=eM.length)
       {
          alert("Please enter a valid e-mail address");
          return false;
       }
   }
  • 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-21T18:19:09+00:00Added an answer on May 21, 2026 at 6:19 pm

    Here’s a link to a working version of your code: JSFiddle link

    The easiest way to correct it is just to make sure you included the javascript in the head of your document, whether it’s a link to an external file (preferably) or just inside the HTML. Then, check for syntax errors in your javascript, this might sometimes cause the code not to execute properly (or at all).

    In your case, you did also try to access fields that did not exist in the code, which caused an error, and when an error is thrown the browser stops validation and just submits the form.

    Here’s the working version of your code:

      <html xmlns="http://www.w3.org/1999/xhtml" >
          <head>
    
          <title>contact.html</title>   
    
            <script type="text/javascript">
                function runValidate() 
     {
    
       //create references
       var fName;
       var mName;
       var lName;
       var email;
       var phone;
       
       fName = document.getElementById('firstName').value;  
           mName = document.getElementById('middleName').value;  
           lName = document.getElementById('lastName').value;  
    
           //validate the first name
           var fN=document.forms["contact_Us"]["firstName"].value;
    
           if (fN==null || fN=="")
           {
              alert("Please fill in first name.");
              return false;
           }
    
           //validate the last name
           var lN=document.forms["contact_Us"]["lastName"].value;
           if (lN==null || lN=="")
           {
           alert("Please fill in last name.");
           return false;
           }
    
    
     }
    
    function isPhoneNumber(phone)
    {
       var str = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
       return str.test(phone);
    }
    
    function email_Val()
    {
       var eM=document.forms["contact_Us"]["email"].value
       var x=eM.indexOf("@");
       var y=eM.lastIndexOf(".");
       if (x<1 || y<x+2 || y+2>=eM.length)
       {
          alert("Please enter a valid e-mail address");
          return false;
       }
    }
              </script>
          </head> 
    <body>
          <div id="right-cont">
    
            <form name = "contact_Us" action="http://nova.umuc.edu/cgi-bin/cgiwrap/ct386a28/eContact.php" method = "post"> 
    
                <div id="style2">
                    <p>Please enter contact information below:</p>                                 
                </div>
    
                <div class="style7">
                    <label>First Name: </label>
                    &nbsp;<br /><input type="text" name = "firstName" id="firstName" tabindex="1" 
                        style="width: 176px" />
                </div>  
    
                <div class="style7">
                    <label>Middle Name: </label>
                    &nbsp;<br /><input type="text" name = "middleName" id ="middleName" tabindex="2" 
                        style="width: 176px" />
                </div>
    
                <div class="style7">
                    <label>Last Name: </label>
                    &nbsp;<br /><input type="text" name = "lastName" id ="lastName" tabindex="3" 
                        style="width: 176px" />
                </div>         
    
                  <div class="style8">
                    <label>Questions and/or comments: </label>
                    &nbsp;<br /> <textarea name = "comment" id = "comment" rows = "10" cols = "60"></textarea>
                  </div>             
    
              <div class =" buttons">
                <input type="submit" value="SUBMIT" onclick="return runValidate();"/><input type="reset" value="CLEAR"/> <br />                
              </div> 
              </div>              
           </form>
       </div>  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, so I have this form that is set to preload a DB record
Okay all, I have a form that I want users to fill out. When
Okay, here is my problem: I have a form that requires to have two
Okay so I have this page with quite a lot of javascript/jQuery in it.
Okay this is what I have so far. I have a form that needs
Okay, I have this textfield form that contains some text. What I need to
Okay I have a large CRUD app that uses tabs with Forms embedded in
I have a classifieds website. In the main page (index) I have several form
I have a form that submits through Ajax, which works perfectly at the moment.
I have a form like this: <form id=form_main name=form_main action=/search/ target=iframe001 method=get onSubmit=reset_and_subm();> Enter

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.