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

Dynamic form... field names and values...

Community Beginner ,
May 14, 2009 May 14, 2009

Boy-Howdy. I wish I had the opportunity to stop by this forum and hang out at a time when I am not having issue, but, alas... I appreciate the brain power of the great minds that populate this forum.

I have an issue: I think I am close on this but cannot identify where my syntax is going awry. Here is a simplified edition of my situation.

I have a form with a set of dropdown menus that filter a recordset. The group of drop downs are dynamic from a database and will vary depending on what category of products a visitor is viewing.

If I browse to FRUIT: I get three options that let me filter for:

Fruit Type

- Apples

- Bananas

- Pears

Fruit Grown By:

- Organic

- Any

Fruit From:

- Domestic

- South America

- European

However, if I browse to LUMBER I get:

Wood Type:

- Pine

- Walnut

- Oak

Wood Prep:

- Pre Cut

- RAW Timber

Wood Origin:

- North America

- South America

- Europe

I have the variable naming and database values worked out. My only issue is when I browse to friuit and select apples I want apples to remain selected as I page through results.

So, the dropdown field names are dynamic. Currently set to zgen1, zgen2, zgen3. I set a variable named sr and increment it to build the progressive 1,2,3 after the field name zgen.

<cfparam name="sr" default="1">
<cfoutput group="ft_id" query="oompa2">
<strong>#f_ftrname#:</strong><br>
<select name="zgen#variables.sr#">
<OPTION value="">select...</OPTION>
<cfoutput>
<OPTION value="#ft_id#_#fs_id#">#ft_options#</OPTION>
</cfoutput>
</select>
<br><br>
<cfset sr=#sr# + 1>

</cfoutput>

But when zgen1 has a value (in this case "Apples") I can't figure out how to dynamically test for the presence of a value for each dropdown. I have dynamically created the field names (cfset xvalue="FORM.zgen#variables.sr#") to test against. However this creates a value of FORM.zgen1, FORM.zgen2, FORM.zgen3 as it loops when I want it to be Apples, Organic, Domestic.

Example:

The code:

<OPTION value="#ft_id#_#fs_id#"<cfif xvalue IS "#ft_id#_#fs_id#"> SELECTED</cfif>>#ft_options#</OPTION>

which is translating to:
<OPTION value="15_5"<cfif FORM.zgen1 IS "15_5"> SELECTED</cfif>>Apples</OPTION>

When I want it to be:

<OPTION value="15_5"<cfif 15_5 IS "15_5"> SELECTED</cfif>>Apples</OPTION>

I hope I am making sense. I would greatly appreciate it if someone could help me noodle this. I have a feeling it is not as complicated as my mind is trying to make it. Thoughts?

425
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
Community Beginner ,
May 14, 2009 May 14, 2009

Wow. I stumped the panel.

No worries though. Problem solved after 3 hours of experimentation.

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
Community Beginner ,
May 14, 2009 May 14, 2009
LATEST

Three selects related type code was not the way to go - because I need each filter to be independent. I created a custom tag that argues the state for each separately up to ten filters.

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