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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:52:27+00:00 2026-06-13T02:52:27+00:00

I am making a contact form that will send an email, but I’m having

  • 0

I am making a contact form that will send an email, but I’m having trouble with making sure people actually are entering data (I know I need to put up more in-depth validation but I want to make sure it’s working first). When the user clicks send, javascript will check to make sure the fields are filled out. If so, then it will validate again on the server side and then send the message (this is working fine), if not it will display an alert and it should not send the message.
However with this javascript, if a field is empty it will display the error message and then send the email anyway. What am I doing wrong here?

<script type="text/javascript">
                function validate() {
                    var x=document.forms['mailcontact']['name'].value; 
                    var y=document.forms['mailcontact']['email'].value; 
                    var z=document.forms['mailcontact']['subject'].value; 
                    if (x == '' || x == null || x == ' name') {
                        alert("You need to enter a name");
                    }
                    else if (y == '' || y == null || y == ' email') {
                        alert("You need to enter your email");
                    }
                    else if (z == '' || z == null || z == ' subject') {
                        alert("You need to enter a subject line");
                    }   
                    else {
                        document.forms['maincontact'].submit();
                    }
                }
            </script>

            <form method="POST" action="mail.php" id="mailcontact">
                <input value=" name" size="25" id="contactname" type="text" name="name" onblur="if(this.value=='') this.value=' name';" onfocus="if(this.value==' name') this.value='';" /> 
                <input value=" email" size="25" id="contactemail" type="text" name="email" onblur="if(this.value=='') this.value=' email';" onfocus="if(this.value==' email') this.value='';" />
                <input value=" subject" size="25" id="contactsubject" type="text" name="subject" onblur="if(this.value=='') this.value=' subject';" onfocus="if(this.value==' subject') this.value='';" />
                <textarea name="message"> message</textarea>
                <input onclick="validate()" value="validate_then_send" type="image" src="../images/sendbutton.png" style=" width: 200px; border: none; position: relative; left: 360px;" />
            </form>​
  • 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-13T02:52:29+00:00Added an answer on June 13, 2026 at 2:52 am
    <script type="text/javascript">
                    function validate() {
                        var x=document.forms['mailcontact']['name'].value; 
                        var y=document.forms['mailcontact']['email'].value; 
                        var z=document.forms['mailcontact']['subject'].value; 
                        if (x == '' || x == null || x == ' name') {
                            alert("You need to enter a name");
                        }
                        else if (y == '' || y == null || y == ' email') {
                            alert("You need to enter your email");
                        }
                        else if (z == '' || z == null || z == ' subject') {
                            alert("You need to enter a subject line");
                        }   
                        else {
                            document.forms['maincontact'].submit();
                        }
                    }
                </script>
    
                <form method="POST" action="mail.php" id="mailcontact">
                    <input value=" name" size="25" id="contactname" type="text" name="name" onblur="if(this.value=='') this.value=' name';" onfocus="if(this.value==' name') this.value='';" /> 
                    <input value=" email" size="25" id="contactemail" type="text" name="email" onblur="if(this.value=='') this.value=' email';" onfocus="if(this.value==' email') this.value='';" />
                    <input value=" subject" size="25" id="contactsubject" type="text" name="subject" onblur="if(this.value=='') this.value=' subject';" onfocus="if(this.value==' subject') this.value='';" />
                    <textarea name="message"> message</textarea>
                    <input onclick="validate();return false;" value="validate_then_send" type="image" src="../images/sendbutton.png" style=" width: 200px; border: none; position: relative; left: 360px;" />
                </form>​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a WordPress theme where every post will have a contact form. The
I need to add a contact form to a website I'm making, and found
Is there a way to capture the amount of screen that is making contact
I'm making a contact page so user's can send message to me when they
I am making a feedback form for my website using php, I thought that
I have been making a form in html that has a checkbox and if
I am making an applicattion that uses gmaps4rails gem which is a simple contact
Well, it may actually be a simple case but I'm having a tough time
I am making a script that POST some XML to another server but I
I'm making a very basic 'contact us' form, and I want to have a

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.