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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:28:08+00:00 2026-06-04T20:28:08+00:00

I have a pretty straight-forward javascript form validation script written: function validateForm(){ var x=document.forms[contactForm][firstname].value;

  • 0

I have a pretty straight-forward javascript form validation script written:

      function validateForm(){
        var x=document.forms["contactForm"]["firstname"].value;
        if (x==null || x==""){
            return false;
        }

        var y=document.forms["contactForm"]["lastname"].value;
        if (y==null || y==""){
            return false;
        }

        var z=document.forms["contactForm"]["emailaddress"].value;
        var atpos=z.indexOf("@");
        var dotpos=z.lastIndexOf(".");
        if (atpos<1 || dotpos<atpos+2 || dotpos+2>=z.length){
            return false;
        }
        var msg_area = document.getElementById("message");
        msg_area.innerHTML = "";
        if (document.getElementById("message").value.length < 20) {
            return false;
        }
        else document.getElementById("contactForm").submit();
    }   

It’s supposed to be validating this form:

 <form name="contactForm" onsubmit="return validateForm()" action="./thankyou.html" method="post">
        <label for="firstName">First Name <sup>*</sup></label>
        <input name ="firstname" id="firstName" type="text" placeholder="First Name" required />
        <label for="lastName">Last Name <sup>*</sup></label>
        <input name ="lastname" id="lastName" type="text" name="lastName" placeholder="Last Name" required />
        <label for="emailaddress">Email address <sup>*</sup></label>
        <input name="emailaddress" id="emailAddress" type="email" placeholder="something@example.com" required />
        <label for="message">Message<sup>*</sup></label>
        <textarea id="message" placeholder="Remember, be nice!" required></textarea>
        <input type="submit" name="submit" value="Email Me!" class="emailsub" />
        <p class="small"><sup>*</sup> denotes a required field.</p>
    </form>

When it’s submitted, it doesn’t seem to actually call the javascript at all. The only thing that it looks for is that it meets the “required” part of the html. I’m pretty new to javascript so it’s probably glaringly obvious where the problem is, but I just can’t locate it myself.

Any help is much appreciated!

p.s. this is for a local website at the moment so the action=”” goes to another html instead of a page to process the message. Is this possibly the problem here?

  • 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-04T20:28:10+00:00Added an answer on June 4, 2026 at 8:28 pm

    The html5 “required” attribute tells the browser to validate before proceeding, read more here. This means that it’s stopping the event before the javascript function is even called (on supported browsers) unless it passes the basic validation (required fields and email).

    If you want the javascript to execute and perform your own validation, you’ll need to remove the “required” attribute. You may also try more complex html form validation. Here is a good article on the subject.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty straight forward task - Given the URL of a video,
Pretty straight forward. I have a rectangle with a label over top of it.
Pretty straight forward question, I have a GtkEntry widget that I want to set
I have a pretty straight forward nested layout. _Layout defines all the global stuff.
Pretty straight forward... I have just setup a Windows Server 2008 r2 Virtual Machine
It's a pretty straight forward question. I have my main window in a WPF
My situation is pretty straight forward. I have a server configured with max_allowed_packet set
I have a 'message' table, where users send and receive messages, pretty straight forward.
Have a pretty straight forward SSIS package: OLE DB Source to get data via
So pretty straight forward but I cant find the answer. Say I have an

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.