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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnChange property for dynamic select boxes? 1

Status
Not open for further replies.

wuz

Programmer
Jul 10, 2000
18
0
0
US
I'm very new to ColdFusion, and I have a question that's stumping me.&nbsp;&nbsp;In my application, I have a category and subcategory (which is related to the category).&nbsp;&nbsp;I want the user to be able to select a choice from a drop-down box that lists both the category and subcategory.&nbsp;&nbsp;But I need to pass the variables separately to the next page.&nbsp;&nbsp;<br><br>When the user comes back to the page, the category and subcategory must reflect what's in the database already.&nbsp;&nbsp;So far, the application does reflect what's in the database, and when they change the selection, the category is passed correctly.&nbsp;&nbsp;But the subcategory is not passed at all.&nbsp;&nbsp;Is there a way to set an onChange property of the select box to update the hidden variable, or is there another way to do this?<br><br>Thanks very much in advance!&nbsp;&nbsp;Here's the part of the code for the queries and select box...<br>-----------------------------------<br><br>&lt;CFQUERY DATASOURCE = &quot;MyApp&quot; NAME = &quot;GetCategory&quot;&gt;<br> SELECT Categories.CategoryName,&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Categories.Category, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Subcategories.Subcategory<br> FROM Categories, Subcategories<br> WHERE Categories.Category = Subcategories.Category<br> ORDER BY Categories.Category, Subcategories.Subcategory<br>&lt;/CFQUERY&gt;<br><br>&lt;CFQUERY name=&quot;ViewProduct&quot; Datasource=&quot;MyApp&quot;&gt;<br>&nbsp;&nbsp;SELECT Items.ProductID, &nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Items.CompanyID, Items.Image, Items.Catalog, Items.Product,<br> Items.UnitPrice, Items.Category,<br> Items.Subcategory,<br>&nbsp;&nbsp;FROM Items<br>&nbsp;&nbsp;WHERE Items.CompanyID=#client.CompanyID#<br>&lt;/CFQUERY&gt;<br><br>&lt;SELECT NAME = &quot;Category&quot;&gt;<br>&nbsp;&nbsp;&lt;CFOUTPUT QUERY = &quot;GetCategory&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;CFIF #ViewProduct.Category# IS #Category# AND&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#ViewProduct.Subcategory# IS #Subcategory#&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;OPTION VALUE = &quot;#Category#&quot; SELECTED&gt;#CategoryName#: #Subcategory#&lt;/option&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;CFELSE&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;OPTION VALUE = &quot;#Category#&quot;&gt;#CategoryName#: #Subcategory#&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/CFIF&gt;<br>&nbsp;&nbsp;&lt;/CFOUTPUT&gt;<br>&lt;/SELECT&gt;<br><br>And further down I have a hidden variable...<br>&lt;INPUT TYPE=&quot;hidden&quot; NAME=&quot;Subcategory&quot; VALUE=#ViewProduct.Subcategory#&gt;
 
You can split the category and subcategory on the server when the form is submitted. Just treat the : between them as the separator.<br><br>example:-<br><br>&lt;cfset test = &quot;monkey : chicken&quot;&gt;<br>&lt;cfset category = left(test, Find(&quot;:&quot;, test)-1)&gt;<br>&lt;cfset subcategory = right(test, Find(&quot;:&quot;, reverse(test))-1)&gt;<br><br>Now just do the above with your form variable and you get the category and subcategory.<br> <p>Russ Michaels<br><a href=mailto:russ@satachi.com>russ@satachi.com</a><br><a href= Internet Development</a><br>For my personal book recommendations visit <br>
 
Thank you so much; this worked great!&nbsp;&nbsp;I appreciate the post so much!&nbsp;&nbsp;That had just been bugging me for a week now, and here it turns out the solution was pretty simple.<br><br>BTW, your site is great; I liked the book recommendations for web design as well as CF.&nbsp;&nbsp;It really helps to know what the professionals are using.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top