Discussion:
Set dropdownlist on page load
(too old to reply)
byronfromwes92
2009-02-26 21:08:16 UTC
Permalink
Hi! I would like to be able to set 3 dropdownlists on page load. Here's what
I have so far:

<cfset form.sFreeState="#state#">
<cfset form.sFreeSubject="#subject#">
<cfset form.sFreeTypeId="#schoolType#">

For some reason, the <select>'s are not set with my values. I am debugging
the page, so I can see my variables in the debug section:

Form Fields:
SFREESTATE=Connecticut
SFREESUBJECT=254
SFREETYPEID=17

What am I missing? Thanks!
-==cfSearching==-
2009-02-26 23:11:31 UTC
Permalink
To preselect values in a select list, you must pass those value to the <select>
list. For example, <cfselect> has a "selected" attribute which is used for
this purpose.

Since we cannot see your code, are you actually doing this?
<cfset form.sFreeTypeId="#schoolType#">
BTW, you do not need either the quotes or # signs in your cfset. Just use

<cfset form.sFreeTypeId = schoolType >
byronfromwes92
2009-02-27 18:19:02 UTC
Permalink
Thanks for the response. Yes, in my code I am attempting to set the select
fields thusly:

<cfset form.sFreeState="#state#">
<cfset form.sFreeSubject="#subject#">
<cfset form.sFreeTypeId="#schoolType#">

The code is using selects, not cfselects. Do I need to use cfselects to pass
a variable to the template to set the displayed value?
-==cfSearching==-
2009-02-27 20:40:32 UTC
Permalink
No, you do not have to use cfselect.
Post by byronfromwes92
<cfset form.sFreeState="#state#">
That simply changes the value of the #form.sFreeState# variable. It will not
pre-select a value in a <select> list. To pre-select an item, you must mark one
of the list's options as "selected".

<select>
<option value="something" selected>Something</option>
....
</select>

http://www.w3schools.com/TAGS/tag_option.asp


of the list's

Loading...