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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:05:45+00:00 2026-06-03T09:05:45+00:00

I seem to be really stuck on something. I have a function to check

  • 0

I seem to be really stuck on something. I have a function to check if all the form input fields are equal to null or “” which is all fine but wanted to see if there is another way of doing it by loading all the fields into a javascript array and then doing a for loop along with an if statement to check if any of the fields are empty, unfortunately I can’t seem to get this to work and wondering if I’ve simply just missed something some where. Here is my code:

function checkempty()
{
    fname = document.getElementById("firstname").value;
    lname = document.getElementById("lastname").value;
    fage = document.getElementById("age").value;
    addressl1 = document.getElementById("addressline1").value;
    addressl2 = document.getElementById("addressline2").value;
    ftown = document.getElementById("town").value;
    fcounty = document.getElementById("county").value;
    fpcode1 = document.getElementById("pcode1").value;
    fpcode2 = document.getElementById("pcode2").value;
    ftelephone = document.getElementById("telephone").value;
    fcomment = document.getElementById("comment").value;

    var myArray = [];
    myArray[0] = fname;
    myArray[1] = lname;
    myArray[2] = fage;
    myArray[3] = addressl1;
    myArray[4] = addressl2;
    myArray[5] = ftown;
    myArray[6] = fcounty;
    myArray[7] = fpcode1;
    myArray[8] = fpcode2;
    myArray[9] = ftelephone;
    myArray[10] = fcomment;

    for(i=0;i<myArray.length;i++)
    {
        if(!myArray[0])
        {
            return true;
        }
    }
    return false;
}

I then use another function:

function checkform()
{
  if(checkempty)
  {
     display_errormessage("One or more fields empty!");
  }
  else
  {
     alert("Thanks for you input!");
  }
 }

The display_errormessage() function is just one that puts an error message into a div at the top of the form to display an error message if the form is incomplete.

Can anyone see where i’ve gone wrong?

Thanks in advance for any help!

Dave.

  • 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-03T09:05:47+00:00Added an answer on June 3, 2026 at 9:05 am

    First, function checkform is not called. The if (checkform) should be if (checkform()) or you will test only test the availability of the function, not the result.

    Then the if (!myArray[0]) should be if (!myArray[i]) to not only test the firstname

    Or better, if (myArray[i].length==0) to be sure to explicitly test for empty string and not just doing an implicit boolean conversion (javascript evaluate 0=="" as 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 created in mysite/new_player.html. It accepts 3 fields, user_name, real_name, and
This may seem really silly to you, I admit, but when discussing the Model-View-ViewModel
I'm really confused about the visitor pattern and its uses. I can't really seem
I'm working in DotNetNuke but this doesn't really seem to be strictly a DNN
I'm struggling to use Chromium Tabs in Cocoa and I really seem to be
This is probably really easy but I can't seem to figure out how to
This is probably a really silly question bu tI can't seem to find an
I know this might seem a controversial question but it really is not meant
I'm really having a problem finding out how to fix this. I cannot seem
I'm sure this is really simple, but I can't seem to get it working.

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.