Results 1 to 3 of 3

Thread: form validation using an array

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    I asked this in VBscript forum, I guess I should have asked it here.
    I have a form w/ 15 text box's.
    four of those text box's are part of an address,it is not a required part of the form but I want to see if the users fills out any part of the address then alert them to fill out all fields.

    I can do this w/ long hand like this:

    if
    (document.form.address.value!=0 &&
    document.form.city.value ==0 &&
    document.form.zip.value ==0)
    {
    alert("fill out the city please")
    document.form.city.focus();
    return false;
    }

    but I would like to use an array and loop through the fields in that manner.

    any suggestions?

    thanks
    pnj

  2. #2
    Addicted Member ShIzO's Avatar
    Join Date
    Apr 1999
    Location
    Bartlett, IL
    Posts
    189
    sorry but you can't use control arrays just like you use them in VB. gotta use individual objects.
    www.HardFind.com -buy/sell/trade your used hardware.

  3. #3
    Guest
    sorry, but you can't NOT have arrays "just like you use them in VB". A web page is nothing but arrays and arrays of arrays, that's one of the great features about them.

    I've put together a stupid page demonstrating object arrays here:http://www.panteravb.com/data/objectarrays.asp. Just right click to view source.

    As far as controls arrays go, they're inherent in javascript. if a form only has one element, it's the 0th element in the forms elements array.

    My advice on the address, name all of the address fields the same name, if there are 4 elements in the address then maybe loop through each. Set an empty flag(a variable called bEmpty set to true) and while looping through the address field array if there is a value in any field flip the flag to false; then recheck the address array if the flag is set to false(indicating one field was not empty) and you hit a field that IS empty then alert the user that if any part of the address is filled in then the whole thing must be filled in. I dunno, just thinkin off the top of my head, but the point is that you have arrays at your disposal.


Posting Permissions

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



Click Here to Expand Forum to Full Width