Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Set dropdownlist on page load

Guest
Feb 26, 2009 Feb 26, 2009
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!
TOPICS
Getting started
908
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 26, 2009 Feb 26, 2009
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 >
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 27, 2009 Feb 27, 2009
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?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Feb 27, 2009 Feb 27, 2009
LATEST
No, you do not have to use cfselect.

> I am attempting to set the select fields thusly:
> <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". Depending on how you generate the list options, you can make the selection more dynamic of course.

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

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources