i'm told document.almostdone.names has no properties?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    i'm told document.almostdone.names has no properties?

    I'm writing something that loops through a form to check if any fields are empty. I got to this:
    [code=javascript]
    function checkEmptyField s()
    {
    names = new Array("first_na me", "last_name" , "country", "city", "dob_d");
    for (i = 0; i < names.length; i++)
    {
    el = document.almost done.names[i].value;
    if(el.empty())
    {
    alert(el + " was empty");
    }
    }
    }
    [/code]
    But i keep being told
    Code:
    document.almostdone.names has no properties
    http://localhost/blog.mahcuz.com/signup/almostdone/js/validateSignUp.js
    Line 6
    
    line 6: el = document.almostdone.names[0].value;
    almostdone is the name of the form.

    Not quite sure ¬_¬
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    The form doesn't have a names array. What you need to use is the elements array, e.g. document.forms["almostdone "].elements[names[i]].value.

    Comment

    Working...