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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:09:51+00:00 2026-06-12T07:09:51+00:00

When a form submit button is clicked, a function to validate all the field

  • 0

When a form submit button is clicked, a function to validate all the field is to be called. Nothing is to happen, however, if the validation fails.

I am using mailto: as my action, does this make a difference?
I would like to get clarification on two things:

  1. Is this the correct way to call a function when clicking the submit button?

    $(document).ready(function(){
        $('#contactForm').submit(function(){
            checkMail();
        });
    });
    
  2. Can I still validate the fields even though I’m using mailto:?

Here is the rest of the code:

function checkEmail(){
    var email = document.contact.email.value;

    if(email == "") {
        document.getElemtById("email_error").innerHTML = "No Email Address";
        return false;
    }
    else {
        document.getElementById("email_error").innerHTML = ""
        return true;
    }
}

HTML:

<form name="contact" action="mailto:exampleemail@hotmail.com" method="post">
    <li>
        <label for="email">Email</label>
    <input id="email" type="text" name="email" placeholder="Enter Email Address">
    </li>
    <span id="email_error"></span>

Further, I don’t get an error message on clicking submit.

  • 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-12T07:09:52+00:00Added an answer on June 12, 2026 at 7:09 am

    No, you need the event handler to return false in case the validation failed. This will prevent the action from being executed, i.e. the mail program from being launched.

    we can cancel the submit action by calling .preventDefault() on the event object or by returning false from our handler.

    Source

    Modify it like this:

    $(document).ready(function(){
        $('#contactForm').submit(function(){
            return validate();
        });
    });
    

    Of course, this implies that the validate() function needs to actually return false in case the validation fails, and true otherwise.

    Further you are missing id="contactForm" on your <form> tag.

    Also, you need to grab the email value correctly:

    var email = $("#email").val();
    

    There’s another mistake: You misspelled getElementById(). Here’s a corrected version:

    function checkEmail() {
        var email = $("#email").val();
    
        if (email == "") {
            document.getElementById("email_error").innerHTML = "No Email Address";
            return false;
        }
        else {
            document.getElementById("email_error").innerHTML = ""
            return true;
        }
    }
    

    Or alternatively, using all jQuery:

    function checkEmail() {
        var email = $("#email").val();
        var $error = $("#email_error");
        if (email == "") {
            $error.html("No Email Address");
            return false;
        }
        else {
            $error.html("");
            return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with a submit button. I have called a function on
I have a form using jquery validation plugin. My submit button has an ajax
First time using Asp.net-mvc and originally followed the NerdDinner tutorial. My form submit button
I have a method, -(void)validateFormInput:(UITextField *)textField that gets called when the form's submit button
I have a form where the submit button triggers a function. Let's call it
I have a form where the submit button triggers a function. Let's call it
im using jquery to submit a php form. during the submission, it will validate
I am unable to determine which form submit button is clicked during an Ajax
I'm using the code below to validate my form. The validation is going great
I have a form with two submit buttons. based on the button clicked i've

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.