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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:23:35+00:00 2026-06-13T21:23:35+00:00

It DOES NOT return false and is not showing the error. See jfiddle http://jsfiddle.net/paYAp/2/

  • 0

It DOES NOT return false and is not showing the error. See jfiddle http://jsfiddle.net/paYAp/2/

My JavaScipt:

function validateForm() {
    var error = "";
    var x=document.getElementById('fname').value;
    var y=document.getElementById('lname').value;
    /*  
    Additional variable defined here, commented out for debugging
    */
    if ((x==null || x=="") || (y==null || y==""))
      {
      error += "-First and last name required. <br />";
      }
      /*
      There were additional statements here, commented out for debugging
     */
    if (error != ""){
      alert(error);
      //document.getElementById('error').innerHTML = "Error: " + error;
      return false;
    }
}

I’ve also attached onsubmit="return validateForm()" to the form.

Can someone please take a look for me and tell me if I’m missing something?

  • 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-13T21:23:37+00:00Added an answer on June 13, 2026 at 9:23 pm

    You may not actually be returning false, you may be returning undefined as you do not return true if validation passes.

    This will trick you into thinking your validation is correct, when it isn’t.

    Adding return true; to the end of the function may prove that you are not returning false after all.

    function validateForm() {
        var error = "";
        var x=document.getElementById('fname').value;
        var y=document.getElementById('lname').value;
        /*  
        Additional variable defined here, commented out for debugging
        */
        if ((x==null || x=="") || (y==null || y==""))
          {
          error += "-First and last name required. <br />";
          }
          /*
          There were additional statements here, commented out for debugging
         */
        if (error != ""){
          alert(error);
          //document.getElementById('error').innerHTML = "Error: " + error;
          return false;
        }
    
        alert("Actually, returning true!");
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As topic suggested, how can I unit test a function that does not return
Type.GetFields() does not return fields in a particular order, but I want to sort
A client credential grant does not return a refresh token (DotNetOpenAuth.OAuth2.AuthorizationServer.PrepareAccessTokenRequest forbids it). But
We got a problem with NUnit 2.5.3: nunit-console.exe does not return after finishing all
This is probably a quicky. Why does this code not return anything? import java.util.Scanner;
C++ does not allow polymorphism for methods based on their return type. However, when
How to catch return hit (enter) on TextBox? The following does not work. I
I may not understand what the return statement does(I thought it just returned a
Before Anything: $.getJSON back button showing JSON return data not the page did not
In the following function, I would like to return false if data = 0

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.