views:

54

answers:

2

I have an drop down in an Update form ‘id=”tak_id”’ being populated from an query”takType”. The drop down box has three options “sms, chat, tweet” with three different values”001,002,003”.

The SELECTED value in the field is being repeated twice.How can I make the SELECTED value appear only once?

The code is below

<cfselect name="tak_id" id="tak_id">
    <cfoutput query="takType">
                      <option >select one</option>
                      <option value="#takType.tak_id#" <cfif takType.tak_id IS tak_id > selected </cfif> > 
                      <cfswitch expression="#takType.tak_id#">
                           <cfcase value="01">SMS </cfcase>
                           <cfcase value="02">chat </cfcase>
                           <cfcase value="03">tweet </cfcase>
                      </cfswitch>
                     </option>
                      <option value="01" >SMS</option>
                      <option value="02" >chat</option>
                      <option value="03" >tweet</option>
    </cfoutput>
    </cfselect>
                </td>                        
            </tr>  

thanks a lot Fransis

+1  A: 

I think you mean to wrap the cfoutputs around the first group only and remove the hard coded three at the bottom. Like this:

<cfselect name="tak_id" id="tak_id"> 
  <option >select one</option>
  <cfoutput query="takType">
  <option value="#takType.tak_id#" <cfif takType.tak_id IS tak_id > selected </cfif> >
  <cfswitch expression="#takType.tak_id#">
    <cfcase value="01">
    SMS
    </cfcase>
    <cfcase value="02">
    chat
    </cfcase>
    <cfcase value="03">
    tweet
    </cfcase>
  </cfswitch>
  </option>
  </cfoutput>
 </cfselect>

Might help to see a dump of that query though, since this relies on those three being in the database.

Max
+1  A: 

Why not move the cfif statement into each of the three hard coded options?

<cfoutput query="takType">
                  <option >select one</option>

                  <option value="01" <cfif takType.tak_id IS "01" >selected</cfif>>SMS</option>
                  <option value="02" <cfif takType.tak_id IS "02" >selected</cfif>>chat</option>
                  <option value="03" <cfif takType.tak_id IS "03" >selected</cfif>>tweet</option>
</cfoutput>
</cfselect>
Jason Tabler