Forums

ASP

This topic is locked

Drop Down Boxes

Posted 05 Dec 2002 14:02:35
1
has voted
05 Dec 2002 14:02:35 Lee Smith posted:
I would like to have two drop down boxes on a form so that when the user selects a value from the first drop down box, it gives them a diffent set of values to select from in the second drop down box.

If you look at the autotrader, www.autotrader.co.uk, website for example, when you select Audi form the Manufacturer Drop down box, you then get a list of the cars that are made by Audi in the Model drop down box.

Any help is greatly appreciated.

Lee Smith

Replies

Replied 05 Dec 2002 22:12:25
05 Dec 2002 22:12:25 Dave Blohm replied:
there are various ways to do this...the EASIEST way is to use show/hide layer JavaScript Behaviors already built into DW...

If you need further help let me know...

Doc
Rangewalk Digital Studios
Replied 06 Dec 2002 04:37:33
06 Dec 2002 04:37:33 LiToZ LiToZ replied:
ummm... there is a very easy JS for doing that using arrays which is really easy to understand and easy to be used... here you go the code, guess it is self explaining <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

&lt;form name="doublecombo"&gt;
&lt;p&gt;&lt;select name="example" size="1" onChange="redirect(this.options.selectedIndex)"&gt;
&lt;option&gt;Technology Sites&lt;/option&gt;
&lt;option&gt;News Sites&lt;/option&gt;
&lt;option&gt;Search Engines&lt;/option&gt;
&lt;/select&gt;
&lt;select name="stage2" size="1"&gt;
&lt;option value="wsabstract.com"&gt;Website Abstraction&lt;/option&gt;
&lt;option value="www.news.com"&gt;News.com&lt;/option&gt;
&lt;option value="www.wired.com"&gt;Wired News&lt;/option&gt;
&lt;/select&gt;
&lt;input type="button" name="test" value="Go!"
onClick="go()"&gt;
&lt;/p&gt;

&lt;script&gt;
&lt;!--

/*
Double Combo Script Credit
By Website Abstraction (www.wsabstract.com)
Over 200+ free JavaScripts here!
*/

var groups=document.doublecombo.example.options.length
var group=new Array(groups)
for (i=0; i&lt;groups; i++)
group[i]=new Array()

group[0][0]=new Option("Website Abstraction","wsabstract.com")
group[0][1]=new Option("News.com","www.news.com")
group[0][2]=new Option("Wired News","www.wired.com")

group[1][0]=new Option("CNN","www.cnn.com")
group[1][1]=new Option("ABC News","www.abcnews.com")

group[2][0]=new Option("Hotbot","www.hotbot.com")
group[2][1]=new Option("Infoseek","www.infoseek.com")
group[2][2]=new Option("Excite","www.excite.com")
group[2][3]=new Option("Lycos","www.lycos.com")

var temp=document.doublecombo.stage2

function redirect(x){
for (m=temp.options.length-1;m&gt;0;m--)
temp.options[m]=null
for (i=0;i&lt;group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}
//--&gt;
&lt;/script&gt;

&lt;/form&gt;



Dats all.... hope that meets what ya want <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Replied 06 Dec 2002 08:35:20
06 Dec 2002 08:35:20 sup ert replied:
Hi!
I got this a few days ago from another 'Guru' on these TalkZones. I tried no. 2 and it works fine.

-------------

There are two ways of achieving this:

1. Filter the second recordset by a common value in the first. This does require the page to refresh though and that can be annoying for the user if they have already entered data into the form.

Here is a link to achieve no.1
www.dmxzone.com/showDetail.asp?TypeId=2&NewsId=3218

2. This is my prefered way and as you say it does require javascript:

Here is a link for no.2
www.macromedia.com/support/ultradev/ts/documents/client_dynamic_listbox.htm


Regards
Vince
Replied 06 Dec 2002 10:15:09
06 Dec 2002 10:15:09 Lee Smith replied:
Thanks for all of your help guys. I shall give all of the suggestions a go and let you know how I get on.

Lee Smith

Reply to this topic