View Full Version : Double Combo Drop Down menu in PHP

10-03-2003, 07:32 AM
Hi I have been searching a lot and no one seems to have the answer to this question so i figured Id try here. I am running a phpBB forum and I have successfuly modded it to ad a regular drop down menu for the profile field. I need a script though, that will allow my users to select a state and once the state is selected it loads a second drop down menu wich contains all the cities. There is a code on this site that does something similar to what i want but it is in javascript and I have tried unsucsessfuly to get the cities to load upon choosing a state. This code is used for opening up a link with the button go but i can do without the button

<form name="doublecombo">
<p><select name="example" size="1" onChange="redirect(this.options.selectedIndex)">
<option>Technology Sites</option>
<option>News Sites</option>
<option>Search Engines</option>
<select name="stage2" size="1">
<option value="http://javascriptkit.com">JavaScript Kit</option>
<option value="http://www.news.com">News.com</option>
<option value="http://www.wired.com">Wired News</option>
<input type="button" name="test" value="Go!"


Double Combo Script Credit
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free JavaScripts here!

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

group[0][0]=new Option("JavaScript Kit","http://javascriptkit.com")
group[0][1]=new Option("News.com","http://www.news.com")
group[0][2]=new Option("Wired News","http://www.wired.com")

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

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

var temp=document.doublecombo.stage2

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)

function go(){


<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript

10-03-2003, 09:23 AM
You would be better off with javascript to do this, if someone choose a wrong option, then they'd have to rechoose it and wait for the page to reload once again.

10-03-2003, 06:20 PM
Are you sure the concept works for the customers using the form? To me, typing in LAS VEGAS is easier than scrolling down almost halfway through a drop down list of cities looking for my city. I can imagine the frustration of someone living in a state like California with hundreds of more cities than Nevada.

Anyway, that's my thought. Sorry I could not be more helpful.

10-03-2003, 09:56 PM
I have placed the java script code in a PHP form page but the thing is that the load function does not work...I am relatively new with PHP and Javascript and I cant seem to see why this is not working... a regular drop down menu works just fine but the double combo doesnt...I have no idea what to do

I used to cities as an example but its specific places in cities really it's detailed so thats why I need this