Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot set selected value in combo 2

Status
Not open for further replies.

accuransx

Programmer
Sep 23, 2000
62
MY
I'm trying to set default value for combo box based on a variable passed to the page. From CF Help doc, it seems easy, just set selected value to one of the value in options values but it didn't work for me :


In my page, this is the combo box code, my combo should select "Pondan" as my selected value since i pass the value "3", BUT still the first option "Lelaki" is selected instead:

<tr>
<td width=&quot;19%&quot; height=&quot;19&quot;><font face=&quot;Tahoma&quot; size=&quot;2&quot;><b>Daerah</b></font></td>
<td width=&quot;81%&quot; height=&quot;19&quot;><cfselect name=&quot;cmbTest&quot; selected=&quot;#a#&quot;><option value=&quot;1&quot;>Lelaki
<option value=&quot;2&quot;>Perempuan
<option value=&quot;3&quot;>Pondan</cfselect></td>
</tr>


Can anybody help me?
 
accuransx,
Try this:
<!-- Name this forhelp.cfm -->

<cfparam name = tn default = 1>
<FORM name='Nomor' ACTION='forhelp.cfm' METHOD='GET'>
<cfoutput>
<select name='tn' onchange='document.Nomor.submit()'>
<option value=1 <cfif #tn# IS 1>selected</cfif>>Tabel 1.
<option value=2 <cfif #tn# IS 2>selected</cfif>>Tabel 2.
<option value=3 <cfif #tn# IS 3>selected</cfif>>Tabel 3.
<option value=4 <cfif #tn# IS 4>selected</cfif>>Tabel 4.
</select>
</cfoutput>
</form>
<cfoutput><strong>Yang Anda pilih adalah Tabel #tn#.</strong></cfoutput>


Goodluck,
mansii
 
accuransx,
The selected parameter of CFSELECT only works if you use the value parameter to pull the values out of a database... which it doesn't look like you're doing, since you're defining your own options (when you define your own options, there's no way for CFSELECT to have control over them).

Either try mansii's method, or create a query that has your data, and hook CFSELECT up that way.
-Carl
 
You did what? &quot;Did it&quot;? Do not reply, please.. I know that you finally &quot;did it&quot;. Congrats!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top