문제

I'm using cfloop to dynamically create/fill in three sets of input fields, plus some radio buttons that are used for a rating system. The input fields work as expected. However I'm having trouble with the radio buttons.

For some reason (and I'm assuming it's a simple reason) the radio buttons don't reflect the values being sent to them. For example: Say I have 3 things I am rating. If the looped values are 5,4,3 the radio buttons are all displaying as if the value being passed to them was 5. It's almost as if all of the field sets are created first and all take the first value (e.g. get checked), as opposed to creating the first field set, insert the value, and then create the second field set and so on (like I would assume in a loop). Again, it works for the everything but the radio buttons. Any insight would be greatly appreciated.

Here is my code:

<cfloop query="postedBy" startrow="1" endrow="4">
    <cfquery name="score" datasource="myDB">
    SELECT Round(sum(leadership)/Count(leadership)) as leadership
           ,  Round(sum(communication)/Count(communication)) as communication
           ,  Round(sum(fairness)/Count(fairness)) as fairness
           , Round(sum(ethics)/Count(ethics)) as ethics
           , Round(sum(competence)/Count(competence)) as competence 
    FROM  score_base 
    WHERE score_ID = '#postedBy.score_id#'
    </cfquery>

    <cfset score_ID=#postedBy.score_id#>
    <cfoutput>id: #postedBy.score_id#</cfoutput>
    <cfoutput>My score: #score.leadership#, #score.communication#, #score.fairness#, #score.ethics#, #score.competence#</cfoutput>

    <cfset counter = counter+1>
    <cfset "currentScore#score.leadership#" = "checked">
    <cfset "currentScoreb#score.communication#" = "checked">
    <cfset "currentScorec#score.fairness#" = "checked">
    <cfset "currentScored#score.ethics#" = "checked">
    <cfset "currentScoree#score.competence#" = "checked">   

     ...
    <div class="rating-wrapper">
        <cfform>
        <label>Leadership</label>
        <cfinput type="radio" class="star" name="leadership" value="1" disabled="disabled" checked = '#currentScore1#'/>
        <cfinput type="radio" class="star" name="leadership" value="2" disabled="disabled" checked = '#currentScore2#'/>
        <cfinput type="radio" class="star" name="leadership" value="3" disabled="disabled" checked = '#currentScore3#'/>
        <cfinput type="radio" class="star" name="leadership" value="4" disabled="disabled" checked = '#currentScore4#'/>
        <cfinput type="radio" class="star" name="leadership" value="4" disabled="disabled" checked = '#currentScore5#'/>
        </cfform>
   </div><!--    END div class="rating-wrapper"    -->
   <div class="rating-wrapper">
       <cfform>
           <label>Communication</label>
           <cfinput type="radio" class="star" name="communication" value="1" disabled="disabled" checked = '#currentScoreb1#'/>
           <cfinput type="radio" class="star" name="communication" value="2" disabled="disabled" checked = '#currentScoreb2#'/>
           <cfinput type="radio" class="star" name="communication" value="3" disabled="disabled" checked = '#currentScoreb3#'/>
           <cfinput type="radio" class="star" name="communication" value="4" disabled="disabled" checked = '#currentScoreb4#'/>
           <cfinput type="radio" class="star" name="communication" value="5" disabled="disabled" checked = '#currentScoreb5#'/>
      </cfform>
   </div><!--    END div class="rating-wrapper"    -->
   <div class="rating-wrapper">
       <cfform>
        <label>Fairness</label>
        <cfinput type="radio" class="star" name="fairness" value="1" disabled="disabled" checked = '#currentScorec1#'/>
        <cfinput type="radio" class="star" name="fairness" value="2" disabled="disabled" checked = '#currentScorec2#'/>
        <cfinput type="radio" class="star" name="fairness" value="3" disabled="disabled" checked = '#currentScorec3#'/>
        <cfinput type="radio" class="star" name="fairness" value="4" disabled="disabled" checked = '#currentScorec4#'/>
        <cfinput type="radio" class="star" name="fairness" value="5" disabled="disabled" checked = '#currentScorec5#'/>
    </cfform>
   </div><!--    END div class="rating-wrapper"    -->
   <div class="rating-wrapper">
      <cfform>
       <label>Ethics</label>
       <cfinput type="radio" class="star" name="ethics" value="1" disabled="disabled" checked = '#currentScored1#'/>
       <cfinput type="radio" class="star" name="ethics" value="2" disabled="disabled" checked = '#currentScored2#'/>
       <cfinput type="radio" class="star" name="ethics" value="3" disabled="disabled" checked = '#currentScored3#'/>
       <cfinput type="radio" class="star" name="ethics" value="4" disabled="disabled" checked = '#currentScored4#'/>
       <cfinput type="radio" class="star" name="ethics" value="5" disabled="disabled" checked = '#currentScored5#'/>
      </cfform>
   </div><!--    END div class="rating-wrapper"    -->
....
</cfloop>
도움이 되었습니까?

해결책

Figured it out: The issue was with my dynamic variables. I needed to reset them at the end of the loop:

<cfset "currentScore#score.leadership#" = "0">
<cfset "currentScoreb#score.communication#" = "0">
<cfset "currentScorec#score.fairness#" = "0">
<cfset "currentScored#score.ethics#" = "0">
<cfset "currentScoree#score.competence#" = "0"> 
</cfloop>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top