I have a set of 2 drop downs. Once a selection is made in the first one, the second one popluates based on the first choice...I also have a a dynamic table on my page that works fine but shows every record from what ever recordset it is based on....here is what I want to happen....'
user makes a choice in first drop down, the second drop down then narrows down and shows those choices ( this all works fine up to this point currently) then when the user selects the second drop down selection. i want my dynamic table to show only records that corespond to the selection in the drop down

Example: user chooses Model of car drop down.....different models are shown in the second drop down...then user selects type model they have then my table only shows parts for this model....Please help ...I know it is pretty simple..i think it is just a simple sql statement or something ..but I am new and this is my first data driven web site to build...thanks so much
If it matters I am using Dreamweaver Cs3

Thanks in advance to all

Well, You mean, based on one dropdown's value, the other dropdown should be populated ? You can use ajax to do this. If you don't have enough time to learn ajax, then the simplest solution would be to submit the page when 'onchange' event occurs in the first dropdown.

<select name="dropdown1" onchange="javascript: dropdown();">
<option value=1>value1</option>
<option value=2>value2</option>
....
</select>

In function dropdown(), get the selected value, assign it to a hidden variable in the form and submit the page.

function dropdown(){
 var value=document.formname.dropdown1.value;
document.formname.hidden.value=value;
document.formname.submit();
}

When the form is submitted, get the hidden value, query the table based on the hidden value condition and list it in dropdown box 2.

$selectedvalue=$_POST['hidden'];
$query="select * from models where car_category='$selectedvalue'";

get the records and populate 2nd dropdown.

Hope it helps..

No, I do not need one drop down to popuate the other....I have this part working fine....I need when a user selects a value in the last drop down for that "value" to be the search criteria for populating my dynamic table.

Example: I have a table called models that has all car models on it. Each car has a unique ID number...when a user selects lets say Honda Accord in the drop down which has a unique id of 2 it populates my dynamic table with a list of all the different parts that could be used on a honda accord by looking for the ID 2 in my parts table....My database is all set up and has relationships and all works fine in the drilling down process in the database. I just need to know what code takes that "variable" that the user selects in the drop down and then passes it on to my dyanmic table with only on parts that go with that record returned

I have copied and pasted my code from my testing page...
also here is the link of what this page look likes..
that table is only a sample of the data...there will be thousands of lines ...and I only want the ones that have the same ID as the model to be diplayed ....( only parts for a certain make/model are displayed once a user has selected the model in the drop down... I think i want this funtion to be maybe "onclick " vs on change sice the second list does change as soon as the first has a selection made... Thanks so far for all the help everyone

<?php require_once('Connections/local.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;


$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);


switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}


mysql_select_db($database_local, $local);
$query_Child = "SELECT * FROM Manufactors";
$Child = mysql_query($query_Child, $local) or die(mysql_error());
$row_Child = mysql_fetch_assoc($Child);
$totalRows_Child = mysql_num_rows($Child);


mysql_select_db($database_local, $local);
$query_Grandchild = "SELECT * FROM Models";
$Grandchild = mysql_query($query_Grandchild, $local) or die(mysql_error());
$row_Grandchild = mysql_fetch_assoc($Grandchild);
$totalRows_Grandchild = mysql_num_rows($Grandchild);


$maxRows_Details = 10;
$pageNum_Details = 0;
if (isset($_GET)) {
$pageNum_Details = $_GET;
}
$startRow_Details = $pageNum_Details * $maxRows_Details;


mysql_select_db($database_local, $local);
$query_Details = "SELECT * FROM Detail";
$query_limit_Details = sprintf("%s LIMIT %d, %d", $query_Details, $startRow_Details, $maxRows_Details);
$Details = mysql_query($query_limit_Details, $local) or die(mysql_error());
$row_Details = mysql_fetch_assoc($Details);


if (isset($_GET)) {
$totalRows_Details = $_GET;
} else {
$all_Details = mysql_query($query_Details);
$totalRows_Details = mysql_num_rows($all_Details);
}
$totalPages_Details = ceil($totalRows_Details/$maxRows_Details)-1;
?>
<?php
if ($row_Grandchild)     {
echo "<SC" . "RIPT>\n";
echo "var WAJA = new Array();\n";


$oldmainid = 0;
$newmainid = $row_Grandchild["ManID"];
if ($oldmainid == $newmainid)    {
$oldmainid = "";
}
$n = 0;
while ($row_Grandchild)     {
if ($oldmainid != $newmainid)     {
echo "WAJA[".$n."] = new Array();\n";
echo "WAJA[".$n."][0] = '".WA_DD_Replace($newmainid)."';\n";
$m = 1;
}


echo "WAJA[".$n."][".$m."] = new Array();\n";
echo "WAJA[".$n."][".$m."][0] = "."'".WA_DD_Replace($row_Grandchild["ID"])."'".";\n";
echo "WAJA[".$n."][".$m."][1] = "."'".WA_DD_Replace($row_Grandchild["Model"])."'".";\n";


$m++;
if ($oldmainid == 0)      {
$oldmainid = $newmainid;
}
$oldmainid = $newmainid;
$row_Grandchild = mysql_fetch_assoc($Grandchild);
if ($row_Grandchild)     {
$newmainid = $row_Grandchild["ManID"];
}
if ($oldmainid != $newmainid)     {
$n++;
}
}


echo "var Grandchild_WAJA = WAJA;\n";
echo "WAJA = null;\n";
echo "</SC" . "RIPT>\n";
}
function WA_DD_Replace($startStr)  {
$startStr = str_replace("'", "|WA|", $startStr);
$startStr = str_replace("\\", "\\\\", $startStr);
$startStr = preg_replace("/[\r\n]{1,}/", " ", $startStr);
return $startStr;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function WA_ClientSideReplace(theval,findvar,repvar)     {
var retval = "";
while (theval.indexOf(findvar) >= 0)    {
retval += theval.substring(0,theval.indexOf(findvar));
retval += repvar;
theval = theval.substring(theval.indexOf(findvar) + String(findvar).length);
}
retval += theval;
if (retval == "" && theval.indexOf(findvar) < 0)    {
retval = theval;
}
return retval;
}


function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function WA_UnloadList(thelist,leavevals,bottomnum)    {
while (thelist.options.length > leavevals+bottomnum)     {
if (thelist.options[leavevals])     {
thelist.options[leavevals] = null;
}
}
return leavevals;
}


function WA_FilterAndPopulateSubList(thearray,sourceselect,targetselect,leaveval,bottomleave,usesource,delimiter)     {
if (bottomleave > 0)     {
leaveArray = new Array(bottomleave);
if (targetselect.options.length >= bottomleave)     {
for (var m=0; m<bottomleave; m++)     {
leavetext = targetselect.options[(targetselect.options.length - bottomleave + m)].text;
leavevalue  = targetselect.options[(targetselect.options.length - bottomleave + m)].value;
leaveArray[m] = new Array(leavevalue,leavetext);
}
}
else     {
for (var m=0; m<bottomleave; m++)     {
leavetext = "";
leavevalue  = "";
leaveArray[m] = new Array(leavevalue,leavetext);
}
}
}
startid = WA_UnloadList(targetselect,leaveval,0);
mainids = new Array();
if (usesource)    maintext = new Array();
for (var j=0; j<sourceselect.options.length; j++)     {
if (sourceselect.options[j].selected)     {
mainids[mainids.length] = sourceselect.options[j].value;
if (usesource)     maintext[maintext.length] = sourceselect.options[j].text + delimiter;
}
}
for (var i=0; i<thearray.length; i++)     {
goodid = false;
for (var h=0; h<mainids.length; h++)     {
if (thearray[0] == mainids[h])     {
goodid = true;
break;
}
}
if (goodid)     {
theBox = targetselect;
theLength = parseInt(theBox.options.length);
theServices = thearray.length + startid;
var l=1;
for (var k=startid; k<theServices; k++)     {
if (l == thearray.length)     break;
theBox.options[k] = new Option();
theBox.options[k].value = thearray[l][0];
if (usesource)     theBox.options[k].text = maintext[h] + WA_ClientSideReplace(thearray[l][1],"|WA|","'");
else               theBox.options[k].text = WA_ClientSideReplace(thearray[l][1],"|WA|","'");
l++;
}
startid = k;
}
}
if (bottomleave > 0)     {
for (var n=0; n<leaveArray.length; n++)     {
targetselect.options[startid+n] = new Option();
targetselect.options[startid+n].value = leaveArray[n][0];
targetselect.options[startid+n].text  = leaveArray[n][1];
}
}
for (var l=0; l < targetselect.options.length; l++)    {
targetselect.options[l].selected = false;
}
if (targetselect.options.length > 0)     {
targetselect.options[0].selected = true;
}
}
//-->
</script>
</head>


<body>
<form id="form1" name="form1" method="post" action="">
<select name="Child" id="Child" onchange="WA_FilterAndPopulateSubList(Grandchild_WAJA,MM_findObj('Child'),MM_findObj('Grandchild'),0,0,false,': ')">
<option value="">Select Manufactor</option>
<?php
do {
?>
<option value="<?php echo $row_Child?>"><?php echo $row_Child?></option>
<?php
} while ($row_Child = mysql_fetch_assoc($Child));
$rows = mysql_num_rows($Child);
if($rows > 0) {
mysql_data_seek($Child, 0);
$row_Child = mysql_fetch_assoc($Child);
}
?>
</select>
<select name="Grandchild" id="Grandchild">
<option value="">Selcet Model</option>
<?php
do {
?>
<option value="<?php echo $row_Grandchild?>"><?php echo $row_Grandchild?></option>
<?php
} while ($row_Grandchild = mysql_fetch_assoc($Grandchild));
$rows = mysql_num_rows($Grandchild);
if($rows > 0) {
mysql_data_seek($Grandchild, 0);
$row_Grandchild = mysql_fetch_assoc($Grandchild);
}
?>
</select>
</form>
<form id="form2" name="form2" method="post" action="">
<table border="1">
<tr>
<td>DetailID</td>
<td>Cycle</td>
<td>Liter</td>
<td>Year</td>
<td>Desc</td>
<td>Fist</td>
<td>Second</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Details; ?></td>
<td><?php echo $row_Details; ?></td>
<td><?php echo $row_Details; ?></td>
<td><?php echo $row_Details; ?></td>
<td><?php echo $row_Details; ?></td>
<td><?php echo $row_Details; ?></td>
<td><?php echo $row_Details; ?></td>
</tr>
<?php } while ($row_Details = mysql_fetch_assoc($Details)); ?>
</table>
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Child);


mysql_free_result($Grandchild);


mysql_free_result($Details);
?>

Edited 3 Years Ago by happygeek: fixed formatting

This article has been dead for over six months. Start a new discussion instead.