form validation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Danny

    form validation

    This is part of a form validation script.

    I put the the call to this functin behind an onclick event on a button, but
    how can I access the names of all the form elements below? For starters, I
    just want to print the names of each element out. IT is not working.
    I know the loop is being iterated, because if I put a dumm prompt with just
    text, it will print each time.
    Thakns

    ..
    ..
    ..
    ..
    ..
    ..

    if (!its_empty(sFu nction))
    {
    oForm.action = sFunction;

    }

    // Loop through all the form elements

    for (counter = 0; counter < oForm.length; counter++) {

    y = (prompt("Name of form element",oForm[counter].name))
    }

    }

    ..
    ..
    ..
    ..


  • Lee

    #2
    Re: form validation

    Danny said:[color=blue]
    >
    >This is part of a form validation script.
    >
    >I put the the call to this functin behind an onclick event on a button, but
    >how can I access the names of all the form elements below? For starters, I
    >just want to print the names of each element out. IT is not working.[/color]

    Telling us "It is not working" is like telling your physician
    that you're sick. What, exactly is not working? What's happening
    that you don't expect, or what is not happening that you do expect?

    Also, it's hard to debug code fragments that refer to variables
    and functions that we can't see. We can't tell if its_empty()
    is breaking something, and have to trust you that oForm is a
    valid reference to a form. It would be better to post a subset
    that shows the problem, and nothing else (ie, we don't need to
    see you set the action).

    Finally, a better way to refer to the name of the i-th form
    element is:
    oForm.elements[counter].name

    [color=blue]
    >if (!its_empty(sFu nction))
    > {
    > oForm.action = sFunction;
    >
    > }
    >
    > // Loop through all the form elements
    >
    > for (counter = 0; counter < oForm.length; counter++) {
    >
    >y = (prompt("Name of form element",oForm[counter].name))
    > }
    >
    >}[/color]

    Comment

    Working...