Counting Form Results

# Thread: Counting Form Results

1. Ronnie Brown Guest

## Counting Form Results

Hi, I have a simple form on my website that has five questions, each with 3 radio buttons in order for the user to provide an answer. How do I count the number of A&#039;s, B&#039;s or C&#039;s etc on the post page, in order to provide a unique statement depending on the answers given?<BR><BR>Thanks in advance<BR><BR>Ronnie

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: Counting Form Results

Is this a programming question or an HTML-type question?<BR><BR>That is, have you got the HTML fine, and you are getting the right results on the ASP page, but you just don&#039;t know how to do the programming?<BR><BR>If so:<BR><BR>&#060;%<BR>ACount = 0<BR>BCount = 0<BR>CCount = 0<BR><BR>For button = 1 To 5<BR>&nbsp; &nbsp; buttonName = "Button" & button<BR>&nbsp; &nbsp; buttonVal = Request.Form(buttonName)<BR>&nbsp; &nbsp; If buttonVal = "A" Then <BR>&nbsp; &nbsp; &nbsp; &nbsp; ACount = ACount + 1<BR>&nbsp; &nbsp; ElseIf buttonVal = "B" Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; BCount = BCount + 1<BR>&nbsp; &nbsp; Else<BR>&nbsp; &nbsp; &nbsp; &nbsp; CCount = CCount + 1<BR>&nbsp; &nbsp; End If<BR>Next<BR>%&#062;<BR><BR>The only "hard" part here is the line<BR>&nbsp; &nbsp; buttonName = "Button" & button<BR>because I have to completely guess at how you named your buttons. If you didn&#039;t give them a "numbered name" of the sort that I presumed (that is, "Button1", "Button2", ...), then you might have to use an array of names and index into the array.<BR><BR>But I think that&#039;s enough guessing on my part from such a small request. Expand the info more if you want more of an answer.<BR><BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
1,849

## Ummmm.

sub processans(var)<BR>select case ucase(var)<BR>case "A"<BR>case "B"<BR>case "C"<BR>case "D"<BR>end select<BR>&#060;%<BR>a = 0<BR>b = 0 <BR>c = 0<BR>d = 0<BR>processans request("questionvar")<BR>processans request("questionvar2")<BR>processans request("questionvar3")<BR>%&#062;<BR><BR>You did not provide the requesting form variable names. This is an efficent way of doing this, but not the only way... More efficent ways depend on how you worded your requesting variable names...<BR><BR>-- Whol

4. Ronnie Brown Guest

## RE: Ummmm.

Hi<BR><BR>Thanks for the quick response - apologies if I never gave enough info.<BR><BR>I have the HTML page ok, all I need is to figure out how to work the process page.<BR><BR>I named my form values like this:<BR><BR>&#060;input type="radio" name="Q1" value="A"&#062;<BR>&#060;input type="radio" name="Q1" value="B"&#062;<BR>&#060;input type="radio" name="Q1" value="C"&#062;<BR><BR>&#060;input type="radio" name="Q2" value="A"&#062;<BR>&#060;input type="radio" name="Q2" value="B"&#062;<BR>&#060;input type="radio" name="Q2" value="C"&#062;<BR><BR>etc.<BR><BR>right up to Q5.<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
1,849

## Using Bill's Example...

Using Bill Wilkinson&#039;s example...<BR><BR>&#060;% <BR>ACount = 0 <BR>BCount = 0 <BR>CCount = 0 <BR>varcount = 2 &#039;This is the number of questions...<BR>For button = 1 To varcount<BR> buttonName = "Q" & button <BR> buttonVal = Request.Form(buttonName) <BR> If buttonVal = "A" Then <BR> ACount = ACount + 1 <BR> ElseIf buttonVal = "B" Then <BR> BCount = BCount + 1 <BR> Else <BR> CCount = CCount + 1 <BR> End If <BR>Next <BR>%&#062; <BR><BR><BR>-- Whol

#### Posting Permissions

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