Joe Lowery
Joe Lowery

Reputation: 572

Get ID (not value) of selected ColdFusion radio button

I've created a quiz in ColdFusion with questions in one table and answers in another; it's multiple choice and each answer is presented as a member of a radio group. I'm looping through my recordset, rsAnswers, to output the radio group. I need to get the database ID of the selected radio button for an Insert operation and can't figure it out.

Here's how I'm outputting the question and answers:

<h3>Question #<cfoutput>#Session.theQuestion#</cfoutput></h3>
<h3><cfoutput>#rsQuestion.rrqQuestion#</cfoutput></h3>
<ol type="A" id="answerList">
  <cfoutput query="rsAnswers">
    <li>
      <label>
        <input type="radio" name="theAnswers" id=#rsAnswers.ID#" value="#rsAnswers.rraValue#" />
        #rsAnswers.rraAnswer#</label>
    </li>
  </cfoutput>
</ol>

If I could retrieve the ID attribute of the selected radio button, I'd be fine, but I don't see a way to do that in CF. What am I missing?

TIA - Joe

Upvotes: 1

Views: 399

Answers (1)

Henry
Henry

Reputation: 32905

When you post the form over, CF only gives you the value of the selected radio button from the form scope. If you need the ID, you should set it as the button value:

<input type="radio" name="theAnswers"
   id=#rsAnswers.ID#" value="#rsAnswers.ID#">#rsAnswers.rraAnswer#</label>

Upvotes: 2

Related Questions