House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Radio buttons in a loop

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Janine Jakim
04/27/2004 12:20 PM

Well I am making a survey. All the questions come out of the database. Also have a 2nd table that is an "answer reference table (1=strongly agree/2=agree/etc)and need to be radio buttons. I have it so it looks pretty but doesn't quite have the functionality I need. What I need: Each question to be able to have a radio button answer. Problem: Only allows one radio button for all the questions combined. So I answer #1. When I answer #2 there no longer is an answer for #1? Make sense? Here's the code. Thanks in advance for any ideas. j <CFLOOP QUERY= "SurveyQuestion"> <TR>                    <TD >  #SurveyQuestion.Question#</TD>             <CFLOOP QUERY="AnswerRef">         <TD>           <INPUT TYPE="radio" NAME="Answer" VALUE="#AnswerRef.AnswerID#">         </TD></CFLOOP>                    </TR> </CFLOOP>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tony Weeg
04/27/2004 12:22 PM

is this a case for checkboxes instead? checkboxes allow for multiple checks, where radio buttons do not. tony Well I am making a survey. All the questions come out of the database. Also have a 2nd table that is an "answer reference table (1=strongly agree/2=agree/etc)and need to be radio buttons. I have it so it looks pretty but doesn't quite have the functionality I need. What I need: Each question to be able to have a radio button answer. Problem: Only allows one radio button for all the questions combined. So I answer #1. When I answer #2 there no longer is an answer for #1? Make sense? Here's the code. Thanks in advance for any ideas. j <CFLOOP QUERY= "SurveyQuestion"> <TR>                    <TD >  #SurveyQuestion.Question#</TD>             <CFLOOP QUERY="AnswerRef">         <TD>           <INPUT TYPE="radio" NAME="Answer" VALUE="#AnswerRef.AnswerID#">         </TD></CFLOOP>                    </TR> </CFLOOP>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tony Weeg
04/27/2004 12:25 PM

you could also append the queryName.currentRow value to the end of the Name="Answer" so that you can have unique names of radio buttons...like this... <CFLOOP QUERY= "SurveyQuestion"> <TR>                    <TD >  #SurveyQuestion.Question#</TD>             <CFLOOP QUERY="AnswerRef">         <TD>           <INPUT TYPE="radio" NAME="Answer#SurveyQuestion.currentRow#" VALUE="#AnswerRef.AnswerID#">         </TD></CFLOOP>                    </TR> </CFLOOP> is this a case for checkboxes instead? checkboxes allow for multiple checks, where radio buttons do not. tony Well I am making a survey. All the questions come out of the database. Also have a 2nd table that is an "answer reference table (1=strongly agree/2=agree/etc)and need to be radio buttons. I have it so it looks pretty but doesn't quite have the functionality I need. What I need: Each question to be able to have a radio button answer. Problem: Only allows one radio button for all the questions combined. So I answer #1. When I answer #2 there no longer is an answer for #1? Make sense? Here's the code. Thanks in advance for any ideas. j <CFLOOP QUERY= "SurveyQuestion"> <TR>                    <TD >  #SurveyQuestion.Question#</TD>             <CFLOOP QUERY="AnswerRef">         <TD>           <INPUT TYPE="radio" NAME="Answer" VALUE="#AnswerRef.AnswerID#">         </TD></CFLOOP>                    </TR> </CFLOOP>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Josh
04/27/2004 12:49 PM

I would append the primary key to the form filed name, rather than the current row. then you know exactly which record it is.  CUrrent row is only unique to that query struct, not the record in the database. -Josh -- Expert Hosting for Less! http://exciteworks.com ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bryan Stevenson
04/27/2004 12:25 PM

Well if you name ALL the radio buttons for each question "Answer" as you have done, you'll have the problem you are having.  Try adding the Question ID to the radio button name (i.e. Answer_Q1, Answer_Q2 etc.) and see where that gets ya ;-) Cheers Bryan Stevenson B.Comm. VP & Director of E-Commerce Development Electric Edge Systems Group Inc. t. 250.920.8830 e. bryan@electricedgesystems.com --------------------------------------------------------- Macromedia Associate Partner www.macromedia.com --------------------------------------------------------- Vancouver Island ColdFusion Users Group Founder & Director www.cfug-vancouverisland.com   Well I am making a survey. All the questions come out of the database. Also   have a 2nd table that is an "answer reference table (1=strongly   agree/2=agree/etc)and need to be radio buttons.   I have it so it looks pretty but doesn't quite have the functionality I   need.   What I need:   Each question to be able to have a radio button answer.   Problem: Only allows one radio button for all the questions combined. So I   answer #1. When I answer #2 there no longer is an answer for #1?   Make sense?   Here's the code.   Thanks in advance for any ideas.   j   <CFLOOP QUERY= "SurveyQuestion">   <TR>              <TD > #SurveyQuestion.Question#</TD>          <CFLOOP QUERY="AnswerRef">   <TD>     <INPUT TYPE="radio" NAME="Answer"   VALUE="#AnswerRef.AnswerID#">   </TD></CFLOOP>          </TR>   </CFLOOP>

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Philip Arnold
04/27/2004 12:36 PM

----- Excess quoted text cut - see Original Post for more ----- That is part of standard Radio Button functionality Name your buttons "Answer_#i#" where "i" is the question number, that way they'll be separate

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Doug James
04/27/2004 12:41 PM

As others have suggested you could add to the name of the radio buttons. If you prepend the number to the name then you can employ the Val() function which: 'Returns a number that the beginning of a string can be converted to. Returns 0 if conversion is not possible.' Doug Janine Jakim wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
jjakim
04/27/2004 01:34 PM

I understand that the name needs to be unique for each row. I thought by adding the QuestionID to the end of the name would do the trick.   But there's something strange about the inner loop (the one that pulls the reference table answers)- it defaults to QuestionID being 1 for all the question. When I test the questionID is correct outside that loop, but reverts to 1 inside that inner loop. Strange.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Tony Weeg
04/27/2004 01:37 PM

what query is returning the questions? are you using that queryName.currentRow for the questions unique id's? tony [mailto:jjakim@albemarle.org] Sent: Tuesday, April 27, 2004 1:33 PM To: CF-Talk Subject: Re: Radio buttons in a loop I understand that the name needs to be unique for each row. I thought by adding the QuestionID to the end of the name would do the trick.  But there's something strange about the inner loop (the one that pulls the reference table answers)- it defaults to QuestionID being 1 for all the question. When I test the questionID is correct outside that loop, but reverts to 1 inside that inner loop. Strange.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bryan Stevenson
04/27/2004 01:40 PM

Yep...this does happen...try setting CurrentQID outside the inner loop and use it as you QID var inside the inner loop...that'll set ya right ;-) Bryan Stevenson B.Comm. VP & Director of E-Commerce Development Electric Edge Systems Group Inc. t. 250.920.8830 e. bryan@electricedgesystems.com --------------------------------------------------------- Macromedia Associate Partner www.macromedia.com --------------------------------------------------------- Vancouver Island ColdFusion Users Group Founder & Director www.cfug-vancouverisland.com   I understand that the name needs to be unique for each row.   I thought by adding the QuestionID to the end of the name would do the trick.   But there's something strange about the inner loop (the one that pulls the reference table answers)- it defaults to QuestionID being 1 for all the question.   When I test the questionID is correct outside that loop, but reverts to 1 inside that inner loop.   Strange.


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

February 08, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29