One combo box based on another

Hi
I got a piece of code off the net which bases one combo box on another, which works perfectly
the only problem i need to base it on records in a table as ive a few hundred records for the “Site” combo box

can anyone help me out on how I would go about changing the below to look at an SQL table

Thanks

<script type=“text/javascript”>
var regiondb = new Object()
regiondb[“2”] = [{value:“1”, text:“Site1”},
{value:“2”, text:“Site2”},
{value:“3”, text:“Site3”},
{value:“4”, text:“Site4”},
{value:“5”, text:“Site5”}];
regiondb[“3”] = [{value:“17”, text:“Site17”},
{value:“18”, text:“Site18”}];

function setCities(chooser) {
var newElem;
var where = (navigator.appName == “Microsoft Internet Explorer”) ? -1 : null;
var siteChooser = chooser.form.elements[“site”];
while (siteChooser.options.length) {
siteChooser.remove(0);
}
var choice = chooser.options[chooser.selectedIndex].value;
var db = regiondb[choice];
newElem = document.createElement(“option”);
newElem.text = “Choose a Site:”;
newElem.value = “”;
siteChooser.add(newElem, where);
if (choice != “”) {
for (var i = 0; i < db.length; i++) {
newElem = document.createElement(“option”);
newElem.text = db[i].text;
newElem.value = db[i].value;
siteChooser.add(newElem, where);
}
}
}
</script>

Your best bet is to query the database and then write a loop with PHP or your server-side language of choice. Inside the loop you would echo back “{value:“2”, text:“Site2”},” dynamically to build your javascript code. Essentially you’re going to re-write this script that you posted using your server-side language before the browser ever starts processing the javascript.