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

how to populate a dropdown box 2 2

Status
Not open for further replies.

yogi564

Programmer
Oct 16, 2001
48
AU
Hi all

I am wondering if someone out there know a proper way to populate a dropdown box after selecting from one, using cold fusion tag. I have tried everything on JAVASCRIPT, but it doesn't pick up the selection base on serveral other selection from the database.

What I have got currently are two dynamic dropdown box with the value populated through the database. Now what needs to happen is, when the user selects something from the first dropdown box the value for the second dropdown should appear from the database base on the first selection and so on. I know it can be easily be done in Javascript in a 'static' way , but I want it dynamic. Thanks

From
yogi
 
CF is as you know, executing server side. JavaScript is executing client side. CF cannot manipulate select boxes or other HTML elements. JavaScript cannot execute queries and get dynamic informations. in order to manipulate drop boxes you have to use client side scripting (JavaScript). In order for JavaScript to work, it has to have all the information required available (for first and second drop box). Conclusion, To make this concept work, you have to execute both queries before serving the template, use the CF and these variables to generate HTML page with JavaScript arrays that will contain the values of both drop boxes. Send THAT HTML to the browser and use JavaScript to manipulate drop boxes... Sylvano
dsylvano@hotmail.com
 
I do not know much JavaScript and I am just picking up CFML and I know even less HTML, but I am going to venture out on this and suggest:

a) What if the options as originally set in dropdown boxes had a link <a href=...> to trigger an action upon selecting a listed option ...

b) If (A) is possible, then let this action call same template with url.variables set to dynamycally populate both boxes based on first loop selection

So, if dropdown box is to behave like a JUMP-MENU, one can then theorize that it can be done!

Should I give up any hope of learning this stuff or am I in the right track? :)

Good luck!

josel
If you have the knowledge, consult and educate those who need it! - Jose Lerebours
 
hi all

Don't worry about this issues anymore I found the soultion for it through this forum from other peoples inquire. thanks everybody.

From
yogi
 
That's nice, but what was it?

Now I want to know more about it as I find it to be a very useful feature ...

Can you forward a pointer or link to the answer(s)?

Thanks!

josel If you have the knowledge, consult and educate those who need it! - Jose Lerebours
 
Hi josel

Is this what you're looking for? You want one drop down selection by the user to change the options in a different drop down? So you can show all the sub categories for a category or something?

Check this:

Change the Application drop down and watch it change the Module drop down. Wrote this a couple years ago for a now bankrupt ebiz. The javascript is sorta cluttered, but you'll see how I used queries to get all of the data for the two drop downs, and then used SWITCH statements in javascript to setup a case for each selection in the Application menu, to trigger a new set of options for the Module menu.

To get the code:

Like i said this was years ago, :) so my code is a little unrefined, but it werx

good luck

good luck
 
Hi all

Source code for the population of dropdown box after selecting the one option.

<cfquery name=&quot;FirstOptions&quot; datasource=#MM_Connection1_DSN# username=#MM_Connection1_USERNAME# password=#MM_Connection1_PASSWORD#>
SELECT Distinct heading FROM T_LANDUSE_LOOKUP
</cfquery>
<CFLOOP index=&quot;x&quot; From = &quot;1&quot; to = &quot;#FirstOptions.recordcount#&quot;>
<CFQUERY name=&quot;Opt#x#&quot; datasource=#MM_Connection1_DSN# username=#MM_Connection1_USERNAME# password=#MM_Connection1_PASSWORD#>
Select subheading
From T_LANDUSE_LOOKUP
Where heading = '#FirstOptions.heading[x]#'
</CFQUERY>
</CFLOOP>

<SCRIPT Language=&quot;JavaScript&quot;>
function updatesel(form)
{
form.land_use_subhead.length = 1;
form.land_use_subhead.selectedIndex = 0;
choice = form.land_use_head.options[form.land_use_head.selectedIndex].value;
<CFLOOP Index=&quot;count&quot; from=&quot;1&quot; to=&quot;#FirstOptions.recordcount#&quot;>
<CFOUTPUT>
if (choice == &quot;#FirstOptions.heading[count]#&quot;)
{
<CFLOOP index=&quot;x&quot; From=&quot;1&quot; to=&quot;#Evaluate('Opt#count#.recordcount')#&quot;>

(form.land_use_subhead.length)++;
form.land_use_subhead.options[form.land_use_subhead.length - 1].text = &quot;#Evaluate('Opt#count#.subheading[x]')#&quot;;


</CFLOOP>
}
</CFOUTPUT>
</CFLOOP>
}
</script>
<select name=&quot;land_use_head&quot;
onChange=&quot;updatesel(this.form)&quot;
width=&quot;250&quot;>
<option value = &quot;%&quot;>All</option>
<cfoutput query=&quot;FirstOptions&quot;>
<option value = &quot;#heading#&quot;>#heading#</option>
</cfoutput>
<select name=&quot;land_use_subhead&quot; width=&quot;250&quot; >
<option value = &quot;%&quot;>All</option>
<cfloop index=&quot;x&quot; from=&quot;1&quot; to=&quot;20&quot;>
<cfoutput>
<option value = &quot;&quot;></option>
</cfoutput>
</cfloop>
</select>
 
Hi strantheman

This code doesn't do anything at all when I click on your Url. What is going on?

From
Yogi
 
Thanks, both of you! I don't have an immediate need for this, but I copied them down, anyway, for future reference. Besides, this seems to be a fairly common request in this forum. Calista :-X
Jedi Knight,
Champion of the Force
 
Hi calista

No problem. You help me out in the security side of things.

from
yogi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top