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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:00:45+00:00 2026-05-22T13:00:45+00:00

I have a form and would like to verify that a few fields that

  • 0

I have a form and would like to verify that a few fields that it contains have an entry.

As such I have the following:

        var requiredFields = array(
                                'Delivery_first_name',
                                'Delivery_last_name',
                                'Delivery_address',
                                'Delivery_city',
                                'Delivery_zip',
                                'Delivery_phone'
        );
        for(var field in requiredFields)
        {
            if(document.ezpay.field.value.length == 0)
            {
                document.ezpay.field.style.cssText = 'background:red;';
            }
        }

However it does not appear to be working. My thoughts are that the field portion of if(document.ezpay.field.value.length == 0)” is not being evaluated.

In other words, the statement is executing as if(document.ezpay.field.value.length == 0) rather than if(document.ezpay.Delivery_first_name.value.length == 0).

Can anyone confirm that belief and more importantly give me some guidance as to why the above is not working?

The goal of the above is to iterate through the defined fields and set the CSS style background to red for any fields that are empty.

Thanks! 🙂

  • 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-05-22T13:00:46+00:00Added an answer on May 22, 2026 at 1:00 pm

    Firstly, you shouldn’t iterate over an array using for...in as that construct is for enumerating object properties.

    Secondly, you are trying to access a property named field when what you want is to access a property whose name is contained in a variable named field. Try:

    for (var i = 0, j = requiredFields.length; i < j; i++)
    {
        if (document.ezpay[requiredFields[i]].value.length == 0)
        {
            document.ezpay[requiredFields[i]].style.cssText = 'background:red;';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a long signup form and would like to hide a few fields
I have a form that I would like all fields to be filled in.
I would like to have a form that can submit to two different action
I have a form that has label values that I would like to pass
I have a form with two selectfields. I would like that when something is
I have a form that edits an instance of my model. I would like
I have two form fields and would like to post those values using jquery
I have a form that I would like to endow with wonderful Ajax-submission goodness
I have form that is loaded into a FancyBox window. I would like to
I would like to have a form triggering submit after a few seconds of

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.