Javascript - Use array to iterate through fields?
<p>I have a form and would like to verify that a few fields that it contains have an entry.</p>

<p>As such I have the following:</p>

<pre><code>        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;';
            }
        }
</code></pre>

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

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

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

<p>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.</p>

<p>Thanks!  :)</p>
