Results 1 to 3 of 3
Cool buttons Forum: Graphics ForumReplies: 11
Form buttons Forum: HTML ForumReplies: 1
multiple submit buttons in single form Forum: HTML ForumReplies: 7
Buttons Forum: Graphics ForumReplies: 2
07-27-2004, 12:33 PM #1
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">
2<input type="RADIO" name="btn1" value="2">
3<input type="RADIO" name="btn1" value="3">
4<input type="RADIO" name="btn1" value="4">
5<input type="RADIO" name="btn1" value="5">
6<input type="RADIO" name="btn1" value="6">
1<input type="RADIO" name="btn2" value="1">
2<input type="RADIO" name="btn2" value="2">
3<input type="RADIO" name="btn2" value="3">
4<input type="RADIO" name="btn2" value="4">
5<input type="RADIO" name="btn2" value="5">
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 appreciate any support!
07-27-2004, 06:30 PM #2
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...
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.
</possible>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?
07-28-2004, 10:18 AM #3
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?