...

View Full Version : triple database combobox / chained selector



zkaya
06-23-2005, 02:39 PM
I have 3 comboboxes. The first combobox gets filled by a 'select' statement
out of a database with php.After a selection is made on combo1, another query must be executed to fill values in combo2. Combo 2 choices is dependant on what is selected in combo 1. Similarly combo3 must be filled with an option selected by combo2. I have tried writing a script but it does not work.
Any help would be much appreciated

<html>
<head>

<script language="JavaScript">
var carMakes = new Array();
var carModels = new Array();
var carBittis = new Array();

<?php

$con = mysql_connect("localhost","root","") or die('Could not connect');
mysql_select_db("uzman_havuzu-db");

$makes = mysql_query("SELECT * FROM makess");
$make_count = 0;
while($make_row = mysql_fetch_array($makes, MYSQL_ASSOC))
{

echo "carMakes[".$make_count."] = \"".$make_row["makee"]."\";\n";


$models = mysql_query("SELECT modell FROM modelss WHERE idd=".$make_row["idd"]);
$model_count = 0;
$num_models = mysql_num_rows($models);

echo "carModels[".$make_count."] = [";
while($model_row = mysql_fetch_array($models, MYSQL_ASSOC))
{
echo " \"".$model_row["modell"]."\"";

$bittis = mysql_query("SELECT bitti_veri FROM bitti WHERE modelss_idd=".$model_row["modelss_idd"]);
$bitti_count=0;
echo "carBittis[".$bitti_count."] = [";
while($bitti_row = mysql_fetch_array($bittis, MYSQL_ASSOC))
{
echo "\"".$bitti_row["bitti_veri"]."\"";
$bitti_count++;
}
echo "];\n";

$model_count++;
if($model_count < $num_models)
echo ", ";
}
echo "];\n";

$make_count++;
}

mysql_close($con);
?>

function populateMakes() {
var makeSel = document.getElementById("makee");
makeSel.length = 0;
for(var i=0; i<carMakes.length; i++) {
makeSel.options[i] = new Option(carMakes[i], carMakes[i]);
}
}

function doChangeOptions() {
var modelSel = document.getElementById("modell");
modelSel.length = 0;
var sel = document.getElementById("makee").selectedIndex;
alert(sel);
var currArr = carModels[sel];
alert(currArr);
for(var i=0; i<currArr.length; i++) {
modelSel.options[i] = new Option(currArr[i], currArr[i]);
}

}

function doChangeOptions1() {
var bittiSel = document.getElementById("bittii");
bittiSel.length = 0;
var sel = document.getElementById("modell").selectedIndex;
alert(sel);
var currArr = carBittis[sel];
alert(currArr);
for(var i=0; i<currArr.length; i++) {
bittiSel.options[i] = new Option(currArr[i], currArr[i]);
}

}

</script>
</head>
<body onload="populateMakes();doChangeOptions();doChangeOptions1();">
<p>Choose a make:
<select id="makee" onchange="doChangeOptions()">

</select>
</p>
<p>Choose a model:
<select id="modell" onchange="doChangeOptions1()">

</select>
</p>
<p>Choose a bitti:
<select id="bittii">

</select>
</p>
</body>
</html>

mothra
06-23-2005, 05:50 PM
It would help if you copy and paste your code again with "[ php ]" and "[ /php ]" tags around it. Makes it much easier to read.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum