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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:47:30+00:00 2026-06-11T05:47:30+00:00

I wrote a javascript function to validate that the user input data is not

  • 0

I wrote a javascript function to validate that the user input data is not empty. The function called “isNotEmpty()” identifies that the text box is empty. But however the main function returns a true statement to the JSP page. Thus the form gets submitted.

The alert no 2&3 fires according the input from the form. but the Alert No1 dose not fires in any circumstances.

Please check on this and assist me.
Thank you.

var firstName;
var data  = new Array(); 

function formEntryValidationTest() {
    firstName = document.forms["regForm"]["firstName"];
    data[0] = isNotEmpty(firstName);//check the first name is empty

    for(var i=0;i<data.length;i++) {
        if(data[i]=="false")
        {
            alert("Check"); //alert No-1
            return false;
        }
    }
}

// this is the function to check whether the input is not empty
function isNotEmpty(obj) {
    if(obj.value!="") {
        alert("true"); //alert No-2
        return "true";
    }
    else
    {
        alert("false");//alert No-3
        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-06-11T05:47:31+00:00Added an answer on June 11, 2026 at 5:47 am

    You’re returning the string "false" rather than the boolean value false, which in JavaScript evaluates to a “truthy” value.

    Change the return statements in isNotEmpty to return true; and return false; and the condition in formEntryValidationTest to if (!data[i]).

    Also, the condition you check in isNotEmpty is too strict. It will return true for undefined and null, which may be the reason your code isn’t working. Change it to something like this:

    function isNotEmpty(value){
      return value ? value.length > 0 : false;
    }
    

    Then pass the input value directly rather than passing the input object itself:

    data[0] = isNotEmpty(firstName.value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a JavaScript function that fires when the user clicks OK in a
I wrote a javascript function that uses the innerHtml of a named div (that
I have a javascript function that posts data to a validation script and grabs
I wrote a simple javascript function that creates a DOM object (in this case
I wrote a simple javascript function to display a progressbar with the help of
How do I write a Javascript function that accepts a variable number of parameters,
I'm trying to write a javascript function that adds some DOM nodes to the
I am trying to write a javascript function with an if statement that will
I wish to write a simple javascript function that toggles the visibility of a
I am a beginner in JavaScript but I wrote two functions that is meant

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.