154 users online (0 members and 154 guests)  

  Results 1 to 3 of 3


  1. Cool buttons    Forum: Graphics Forum
    Replies: 11
  2. Replies: 0
  3. Form buttons    Forum: HTML Forum
    Replies: 1
  4. multiple submit buttons in single form    Forum: HTML Forum
    Replies: 7
  5. Buttons    Forum: Graphics Forum
    Replies: 2
  1. #1
    woodknut's Avatar

    Join Date
    Dec 2003

    How do I iterate through all Form buttons?

    I have written a survey page within an HTML FORM that I want to submit to an ASP page to write the form data to a text file.

    The good news is that the ASP page writes data to a text file.

    The bad news is that I'm not getting it all. Or more specifically I need to deal with "undefined" data.

    HTML code snippet (there are actually 30 radio groups) :
    <form action="survey.asp" method="post">
    1<input type="RADIO" name="btn1" value="1">&nbsp;
    2<input type="RADIO" name="btn1" value="2">&nbsp;
    3<input type="RADIO" name="btn1" value="3">&nbsp;
    4<input type="RADIO" name="btn1" value="4">&nbsp;
    5<input type="RADIO" name="btn1" value="5">&nbsp;
    6<input type="RADIO" name="btn1" value="6">
    1<input type="RADIO" name="btn2" value="1">&nbsp;
    2<input type="RADIO" name="btn2" value="2">&nbsp;
    3<input type="RADIO" name="btn2" value="3">&nbsp;
    4<input type="RADIO" name="btn2" value="4">&nbsp;
    5<input type="RADIO" name="btn2" value="5">&nbsp;
    6<input type="RADIO" name="btn2" value="6">

    ASP code snippet:
    For x = 1 to Request.Form.Count
    strPageEntry = strPageEntry + Request.Form.Item(x)
    strPageEntry = strPageEntry + ","

    The variable strPageEntry is then written to the text file.

    The problem is that the value Request.Form.Count is not the count of all the form elements...it is only the elements that the user has clicked a button...so I am only getting the response to clicked on buttons.

    What value can I use to iterate through ALL the form elements (buttons in this case)? I have tried "for each item in" but didn't work...though I may have used the wrong syntax.

    Ok, I get the fact that the buttons are undefined when not clicked and therefore are not concatenated to the string.
    How can I check for an unclicked button (undefined)? request.form.item(x).checked ?
    If the button was not clicked, I would like to add a "0," to the concatenated string.

    I would rather not do any form validation to ensure all the buttons are clicked via javascript (or whatever). Its ok if the survey question goes unanswered. I would like to simply store a "0" for any unanswered questions.

    I appreciate any support!

  2. #2
    QuietDean's Avatar

    Join Date
    Oct 2000
    Bournemouth, UK
    Interesting question.
    <wrong answer>
    Personally, I would try this (Assuming that the amount of radio buttons is constant, if not just pass it thru via a hidden form field) -

    Change your for loop so instead of counting the submitted form elements, its counting as high as the number of radio buttons. You can then test for a value...NO that wont work. It would shift all the submitted answers to to the top of the array...
    </wrong answer>

    Ah. The simple approach. Have an extra radio button called 'No answer' in each group which is selected by default. With a value of 0. That should work.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    woodknut's Avatar

    Join Date
    Dec 2003
    Thank you for your thoughts Dean.

    I've tried a couple things with some success:

    1) A hidden form field with the actual number of buttons. If the number of questions on the survey changes so will this number, either way I'll have to edit the page.
    As you stated the items then appear out of order. What kind of stupid memory management is that? Who would design a language that can't properly access array elements? ;~)

    2) A hidden form field within the radio group with a default value of "0". This works great if the button is not selected; however, when the user selects a button for a question...I get both the "0" value AND whichever the user selected.

    After reading a number of other Internet sources it would appear that the "best practice" concerning radio buttons is to provide a default setting as you have suggested. There's always a good reason for best practice, eh?

    Thanks again!

Tags for this Thread