|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Radio buttons in a loop
Well I am making a survey. All the questions come out of the database. AlsoJanine Jakim 04/27/04 12:20 P is this a case for checkboxes instead?Tony Weeg 04/27/04 12:22 P you could also append the queryName.currentRow value to the end of theTony Weeg 04/27/04 12:25 P I would append the primary key to the form filed name, rather than theJosh 04/27/04 12:49 P 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 ;-)Bryan Stevenson 04/27/04 12:25 P > From: Janine JakimPhilip Arnold 04/27/04 12:36 P As others have suggested you could add to the name of the radio buttons.Doug James 04/27/04 12:41 P I understand that the name needs to be unique for each row.jjakim 04/27/04 01:34 P what query is returning the questions?Tony Weeg 04/27/04 01:37 P 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> 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> 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> 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 ----- 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> ----- 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 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 ----- 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. 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. 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.
|
February 08, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||