Results 1 to 9 of 9

Thread: Forms Collection??

  1. #1

    Thread Starter
    Addicted Member wernerh's Avatar
    Join Date
    Sep 2000
    Posts
    170

    Question Forms Collection??

    How can I run through all the inputs in my form to validate them for the same condition?

    Can I use the form.elements

    Something like:
    for i = 0 to form.elemets.count
    if form.elements(i).value = "" then
    window.alert "Enter data!"
    end if
    next

    It gives me an error stating that object doesnt support this property. What is wrong or what other way is there to do it?
    I Have alot of textboxes on my form and dont want to check each on inividualy!

  2. #2
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    Code:
    For Each Item In Request.Form
      If Len(Item) = 0 Then '//Item is Empty
      'If Item.Value = "" Then - will work too, i think.
        Alert "Enter Data!"
      End If
    Next

    r0ach™
    Don't forget to rate the post

  3. #3

    Thread Starter
    Addicted Member wernerh's Avatar
    Join Date
    Sep 2000
    Posts
    170
    I actually want to do it in client side script on my form_Onsubmit function so the request.form will not work

  4. #4
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    Sorry. I kinda copied that out of one of my pages.

    Try Window.Form instead of Request.Form

    r0ach™
    Don't forget to rate the post

  5. #5
    Lively Member
    Join Date
    Jan 2001
    Posts
    118
    I see you are from South Africa. Where are u from ?

    But here is the code.

    Sub btn_click()

    For each checkbox in document.formname

    if checkbox.type = "checkbox" then
    if checkbox.checked = true then
    Msgbox Checkbox.ID & " is checked!"

    End if
    End if


    End Sub

    This will loop thru all the checkbox to see which one(s) is ticked. You can change it to any control on the form.

  6. #6
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    Sundance Kid:

    Are you from SA? 'Cos if you are, then we all are! Hehehe

    r0ach™
    Don't forget to rate the post

  7. #7
    Lively Member
    Join Date
    Jan 2001
    Posts
    118
    Magtig... rerig. Are you guys Afrikaans or English? Where do you guys work?

  8. #8
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722
    Ek is afrikaans gebore, but my Fiancée is english so I'm bi-lingual.

    noGuru is also from SA. He's a personal friend of mine. We (mainly me) are working on a cool website, which we'll upload when it's done.

    I'm from Pretoria. You guys?

    r0ach™
    Don't forget to rate the post

  9. #9
    Lively Member
    Join Date
    Jan 2001
    Posts
    118
    Skop my krippel. Ek is ook van Pretoria. Centurion. What website do you guys work on?

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