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

DROPDOWN LISTS HELP

Status
Not open for further replies.

kingjjx

Programmer
Joined
Sep 18, 2001
Messages
181
Location
US
Hi, Can someone tell me how to create 2 drop down lists in which the list will be populated from a database and the 2nd drop down is dependent on the 1st dropdown list. the 2nd dropdown list can be in antoher page.
EXAMPLE:

In the first dropdown list .. user can choose from HONDA, TOYOTA, MERCEDES ...

If the user chooses, HONDA and click search .. it will go to a 2nd page with another dropdown menu that will give the user list of ONLY HONDA MODELS ie CIVIC, ACCORD, PRELUDE ..


I figured , putting the 2nd dropdown menu will make it easier but if anyone can tell me how to do it in the same page it would be great. I just want this to work.

Right now I have it that the 2nd dropdown list, lists all the models of all cars which can be a pretty long list.

Can Anyone please help me ...
thanks
-jon
 
Here is my Cut-n-Paste verions of this:

I've used it a million times. Works great:


<CFQUERY name=&quot;FirstOptions&quot; Datasource=&quot;DataB&quot;>
Select *
From tblProject
</CFQUERY>
<CFLOOP index=&quot;x&quot; From = &quot;1&quot; to = &quot;#FirstOptions.recordcount#&quot;>
<CFQUERY name=&quot;Opt#x#&quot; datasource=&quot;DataB&quot;>
Select *
From tblTimeDetail
Where ProjectID = #FirstOptions.ProjectID[x]#
</CFQUERY>
</CFLOOP>


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

(form.Two.length)++;
form.Two.options[form.Two.length - 1].text = &quot;#Evaluate('Opt#count#.Time[x]')#&quot;;
form.Two.options[form.Two.length - 1].value = &quot;#Evaluate('Opt#count#.TimeDetailID[x]')#&quot;;

</CFLOOP>
}
</CFOUTPUT>
</CFLOOP>
}
</script>


<FORM METHOD=&quot;POST&quot; ACTION=&quot;look2.cfm&quot; NAME=&quot;myform&quot;>
<SELECT NAME=&quot;One&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;#ProjectID#&quot;>#Name#</OPTION>
</CFOUTPUT>
</SELECT>
Look
<SELECT NAME=&quot;Two&quot; WIDTH=&quot;250&quot; >
<OPTION VALUE = &quot;%&quot;>All</OPTION>
<CFLOOP index=&quot;x&quot; From=&quot;1&quot; to=&quot;6&quot;>
<CFOUTPUT>
<OPTION VALUE = &quot;&quot;>000000000000000000000000</OPTION>
</CFOUTPUT>
</CFLOOP>
</select>
</FORM>


All you have to do is go through and change the Queries (at top) and change the names of the Fields in the javascript function. This does the same thing as the example that Clista pointed you at, only it does it dynamically from your database. Let me know if you have any trouble converting this for your use.

have fun. hope it thelps.
 
hey tlhawkins , what do i need to write in the actin page ?
i mean .. in the form method=post action=look2.cfm

whats the code for look2.cfm ???


thanks
 
HEY, I GOT THE DROP DOWN TO WORK BUT THE FIRST DROPDOWN DUPLICATES THE NAMES. EXAMPLE, THE 1ST DROPDOWN IS THE MAKE OF THE CAR AND THE 2ND IS THE MODEL. WHEN U CHOOSE THE 1ST DROPDOWN, IT SHOWS HONDA REPETITIVELY. HOW DO I MAKE IT NOT REPEAT ?

THANKS
 
Hi Kingjjx,

I've been away for a couple days. Sorry it took me so long to get back to you.

From what you said is happening it sounds like you are not using the index in one of your loops. Compare your code to mine (Above) and make sure you have the [x] behind the variables when it is needed.

If that doesn't help please post what you have and I'll take a look.

hope I can help.
 
Status
Not open for further replies.

Similar threads

  • Locked
  • Question Question
Replies
5
Views
489
  • Locked
  • Question Question
Replies
4
Views
416

Part and Inventory Search

Sponsor

Back
Top