Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    more Vorm Falidation ...

    Hi all,

    OK, here's the thing. I have a couple of forms on my website and I'm attempting to write a single piece of general validation code to work on both of them. I'm attempting (and this is my first foray into this area) to use general document.forms.elements and iterating loops to do this.

    1st, the call. The function is called from the onSubmit tag in the HTML - I pass the form name to identify the form we're working with:

    onSubmit="return checkValidation('RequestForInformation');"

    My actual validation code looks as follows:

    requiredFieldsArray = new Array("Title","FirstName","Surname","Email","Company","Phone","ResearchPapers");

    function checkValidation(formID)
    { formDOM = document.forms[formID];

    for (i=0; i<=formDOM.elements.length; i++)
    { if (formDOM.elements[i].name == requiredFieldsArray[i])
    { if (formDOM.elements[i].type == "text")
    { if (formDOM.elements[i].value == "test") { alert("Please enter a value in the "+requiredFieldsArray[i]+" field"); return false; }
    }
    if ((formDOM.elements[i].type == "text")&&(requiredFieldsArray[i] == "Email")){}
    if (formDOM.elements[i].type == "selection"){}
    if (formDOM.elements[i].type == "checkbox"){}
    }
    }
    return true;
    }

    However, there are two problems happening here:
    1. in the Frontpage preview, afer I enter the value "test" and click Submit, I get the error :
    formDOM.elements[...].name is null or not an object

    2. when testing in a web browser, however, no errors come up at all and whn the sumbit button is pressed, my confirmation page is served up and it doesn't look like the onSubmit got anywhere near my validation code.

    Could this be something to do with using the .name property on elements[i]? Is this not supported? Any ideas?

    if you want to look at the working page, got to:
    RequestForInformation.html

    Cheers,

    Azz
    code, debug, dubug, debug, *SIGH* debug, debug ...

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi all,

    fixed it - don't worry about it

    cheers

    Azz
    code, debug, dubug, debug, *SIGH* debug, debug ...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •