Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Radio Button Values

Status
Not open for further replies.

kloner

Programmer
May 15, 2000
79
AU
Hi all,

I have a question regarding how to display the checked value of a radio button to the next page (and CFMAIL). The following code is generated and displays a series of questions pulled form a DB.

<tr valign=&quot;top&quot;>
<td><font class=&quot;body&quot;>Questions</font></td>
<td nowrap>
<center>
<font class=&quot;smallcopy&quot;>Not<br>
Relevant </font>
</center>
</td>
<td nowrap>
<center>
<font class=&quot;smallcopy&quot;>Strongly<br>
Disagree </font>
</center>
</td>
<td nowrap></td>
<td nowrap>
<center>
<font class=&quot;smallcopy&quot;>Strongly<br>
Agree </font>
</center>
</td>
</tr>

<cfloop Query=&quot;questions&quot;>
<cfoutput>
<tr valign=&quot;top&quot;>
<td>
<div align=&quot;right&quot;><font class=&quot;body&quot;>#question_text#</font></div>
</td>
<td nowrap>
<center>
<font class=&quot;body&quot;>
<cfinput type=&quot;radio&quot; name=&quot;#question_id#&quot; value=&quot;N&quot;>
</font>
</center>
</td>
<td nowrap>
<center>
<cfinput type=&quot;radio&quot; name=&quot;#question_id#&quot; value=&quot;1&quot;>
<cfinput type=&quot;radio&quot; name=&quot;#question_id#&quot; value=&quot;2&quot;>
</center>
</td>
<td nowrap>
<center>
<cfinput type=&quot;radio&quot; name=&quot;#question_id#&quot; value=&quot;3&quot; checked>
</center>
</td>
<td nowrap>
<center>
<cfinput type=&quot;radio&quot; name=&quot;#question_id#&quot; value=&quot;4&quot;>
<cfinput type=&quot;radio&quot; name=&quot;#question_id#&quot; value=&quot;5&quot;>
</center>
</td>
</tr>
</cfoutput>
</cfloop>

So for example the page would look like this : (each question's radio buttons have a value(1 to 5) and a name(#question_id#)

Question 1 goes here Radio1 Radio2 Radio3 Radio4 Radio5
Question 2 goes here Radio1 Radio2 Radio3 Radio4 Radio5
Question 3 goes here Radio1 Radio2 Radio3 Radio4 Radio5
Question 4 goes here Radio1 Radio2 Radio3 Radio4 Radio5

When i hit 'submit' validation is run (for other stuff), and I want to get the results of each question, like this:

Question 1 : The rating given was (5)
Question 2 : The rating given was (3)
Question 3 : The rating given was (1)
Question 4 : The rating given was (2)

How do I get the results of the checked radio buttons? Do I have to use a List? If someone has similar examples I would really appreciate them showing me how they would do such a task.

Regards, [sig]<p>Matthew Wall<br><a href=mailto: > </a><br><a href= > </a><br> [/sig]
 
Don't know if there are a bunch of other fields on the form, but if not you can loop through the form fields referencing the form as an structure. I've done something similar in a number of places. Here's a sample:

<cfloop collection=&quot;#form#&quot; item=&quot;Loop_item&quot;>
<cfoutput>
<cfif #loop_item# NEQ &quot;fieldnames&quot; and #loop_item# NEQ &quot;submit&quot;>
<br> the question is: #LOOP_item#<br> and the answer is: #form[loop_item]#<br>
</cfif>
</cfoutput>
</cfloop>

I use cfif to ignore fields I don't want. You can get really tricky on forms which have a bunch of other fields you don't want if you name all the fields you want to reference in the loop with some common prefix, like L_ (so the name would be L_name) Then have your cfif look only for items in the collection containing L_ or whatever you chosen pattern is.

Hope that helps - this advice is coming from someone who has been using CF under a month, so there are probably better ways... [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top