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

Dynamic Drop Down

Status
Not open for further replies.

btgroup

MIS
Jan 21, 2003
64
US
Does anyone know how to create a dynamic drop down list from a query if the item and value parameters are given ahead of time? I don't want to hard code the item and value of a select list so that I can consistently use the same custom tag with a new query, item field, and value field.

For instance, I would call the tag as follows:
<cf_dbdropdown sql=&quot;select * from states&quot; itemfield=&quot;state_name&quot; valuefield=&quot;stateid&quot;>

Thanks in advance.
 
You are currently populating from a query, so maybe I'm not getting exactly what you want to do. There are two alternatives in the FAQ area, here's one, faq232-1158

DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
This can be done almost automatically if you're using CFFORM and CFSELECT. I wrote a FAQ on it. faq232-3628
 
Wow! The cfselect tag is exactly what I am trying to do. Are there any drawbacks to using cfform and cfselect (like the need to download an applet, etc.)? If so, do you know of any way to do the same thing using a custom tag and standard HTML forms?

Thanks for your help!!
 
In earlier versions of CF (4.5 and older, I believe), you did have to download an applet. But it's the same one used in a lot of the CF Administrator stuff, so if your computer's ever played in the CF Admin, chances are you already have it. It was a simple &quot;enablecab=&quot;yes/no&quot;&quot; attribute used in the cfform tag, and Cold Fusion would check for the applet and prompt for a download if the user didn't have it. I'm fairly sure it's the same way in CF 5.0 and I don't know about MX.

CFFORM will also do validation on your form fields for you. Just set &quot;required=&quot;Yes&quot;&quot; in your cfinput fields and it will write the javascript for you. Some people say it's great, some say it's bulky and unnecessary code. It just depends on your needs and opinions. Personally, I use it every chance I get because I don't like Javascript, but that's just me.

To do it with a standard HTML form, you really wouldn't need a custom tag. Here's another FAQ on how to do that: FAQ232-1158

But basically, it winds up being something like this:

<cfquery datasource=&quot;#datasource# name=&quot;list&quot;>
SELECT Item, Value
FROM ItemTable
ORDER BY Item
</cfquery>

<form name=&quot;item_search&quot;>
<select name=&quot;ItemMenu&quot;>
<option value=&quot;0&quot;>items:</option>
<cfoutput query=&quot;list&quot;>
<option value=&quot;#Value#&quot;>#Item#</option>
</cfoutput>

</select>
</form>

I copied and pasted the above code from the FAQ I mentioned. By the way, I think this is the same FAQ that DeZiner was talking about earilier.

Hope this helps!
 
Thank you very much. You guys are a great help. I would like to avoid cfselect because of the all but inevitable maintenance issues that arise from downloading applets.

The FAQ article clued me in on how to change my original problem. I can just make the query include similar names each time and re-use the same code over and over. As an example, if my sql query is &quot;select state_name as item, stateid as value from states&quot;, then I can write the custom tag to make sure the query always has an item and value field. I can call the tag anytime I need a select drop down.

Thanks again!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top