Forum Moderators: open

Message Too Old, No Replies

dynamic double dropdown menus

         

ryan_b83

8:11 pm on Feb 4, 2007 (gmt 0)

10+ Year Member



Here is my example, i need to have 2 dropdown menus, and depending on the first drop down, the second drop down's values change... The data list in this format (there are hundreds of variables, but here are just a few). Anyone know a dynamic way to make this work with this data layout? Thanks

$b[1][0] = "Agassiz Brewing";
$b[1][1] = "Bison Blonde Lager";
$b[1][2] = "Catfish Cream Ale";

$b[3][0] = "Alley Kat Brewing Company";
$b[3][1] = "Alley Kat Amber";
$b[3][2] = "Aprikat";

$b[4][0] = "Big Rock Brewery";
$b[4][1] = "Alberta Genuine Draft";
$b[4][2] = "Big Rock Honey Brown";

ericjust

8:50 pm on Feb 4, 2007 (gmt 0)

10+ Year Member



You could do something like:

<script language="javascript">
<!--

var listData; // populate with list data

function buildList(index){
var theList = document.getElementById('secondList');
var theList.innerHTML = '';
for (var i=0;i<listData[index].length;i++){
var list_item = document.createElement('LI');
var list_text = document.createTextNode(listData[index][i]);
list_item.appendChild(list_text);
theList.appendChild(list_item);
}
}

//-->
</script>

This is untested code... and not the most efficient - but might point you in the right direction. You can have the onclick attribute of each LI in the first list call this function passing it the index of the array you want to populate the second list with (i.e. <li onclick="buildList(2)">My Name</li>).

ericjust

8:55 pm on Feb 4, 2007 (gmt 0)

10+ Year Member



Or....

<script language="javascript">
<!--

var listData; // populate with list data

function buildList(index){
var theList = document.getElementById('secondList');
var newInnerHTML = '';
for (var i=0;i<listData[index].length;i++){
newInnerHTML += '<li>';
newInnerHTML += listData[index][i]; // not escaped!
newInnerHTML += '</li>';
}
var theList.innerHTML = newInnerHTML;
}

//-->
</script>

ryan_b83

1:02 am on Feb 7, 2007 (gmt 0)

10+ Year Member



awesome, thanx alot!

FrEaKmAn

7:26 am on Feb 10, 2007 (gmt 0)

10+ Year Member



Hi, I have same similar problem. I have 'packages' table with package name, price for 1,3,6,12 months so 5 inputs. Now I export packages names as a drop down menu, so I would like that when I select one, the next drop down menu is updated with new prices, and if I select another one the next drop down box update again and so on. I found few forms that can do this, but I can't or I don't know how to integrate them into php, where I load data from database.