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 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts

    looping through forms collection

    I am doing as follows

    For x = 1 to Request.Form.Count
    response.write request.form.key(x) & "<hr>"
    next

    for some reason this does not pick up on checkboxes that are not checked -- why not?

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    That's because checkboxes that are not checked aren't sent to the server. Therefore they won't come up in the collection.

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,466
    Thanks
    15
    Thanked 0 Times in 0 Posts
    and no way to get the names?

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope, not if they are not sent.

    If you want required fields then setup a hidden form element or array to hold the fieldnames that you require.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by degsy View Post
    Nope, not if they are not sent.

    If you want required fields then setup a hidden form element or array to hold the fieldnames that you require.
    You don't need that to validate checkboxes that are required.
    If you request.form a checkbox that is not checked, its value is empty. So you can validate it if it is checked by checking if it has a value.
    Code:
    If Request.Form("mycheckbox")="" Then 'unchecked
       Response.Write "The checkbox is unchecked!"
    Else 'checked
       Response.Write "The checkbox is checked!"
    End If
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You don't need that to validate checkboxes that are required.
    But that's exactly what you have done.

    What you've done is hardcoded the checkbox name into your script to see if the checkbox has been submitted or not and to set a value for a variable.

    Maybe I could have used compare instead of validate, but the objective is to get a value for the variable. e.g. Yes or No.


  •  

    Posting Permissions

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