Hi there I have a script that dynamically populates a drop down field. When selected it populates a subcategory drop down field. When selected in the sub category drop down field I want to use the onchange function to take it to a details.php page. I am not sure how to assign the subcategory id to be called so it goes it details.php?id=1
Here is my code that I have so far:
<?PHP
include ('includes/config.php');
//Query for occasions
$query_occasions = "SELECT occasion_type, id FROM occasion ORDER BY occasion_type ASC";
$occasions = mysql_query($query_occasions,$dbconn) or die(mysql_error());
?>
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
<!--
function BodyLoad() {
var select = document.FormName.occasion_type;
select.options[0] = new Option("Choose One");
select.options[0].value = 0;
<?PHP
$ctr = 1;
While( $Row = mysql_fetch_array($occasions) ) {
echo "select.options[$ctr] = new Option(\"$Row[occasion_type]\");\n";
echo "select.options[$ctr].value = \"$Row[occasion_type]\";\n";
$ctr++;
}
?>
}
function Fill_Sub() {
var main_select = document.FormName.occasion_type;
var sub_select = document.FormName.recipe_type;
if( main_select.options[main_select.selectedIndex].value != 0 ) {
sub_select.length = 0;
}
<?PHP
$query_occasions = "SELECT occasion_type, id FROM occasion ORDER BY occasion_type ASC";
$occasions = mysql_query($query_occasions,$dbconn) or die(mysql_error());
while( $Row = mysql_fetch_array($occasions) ) {
?>
if( main_select.options[main_select.selectedIndex].text == "<?PHP echo $Row[occasion_type]; ?>" ) {
<?PHP
$query_recipe_type = "SELECT recipe_type FROM recipe_type WHERE occasion_id = '$Row[id]' ORDER BY recipe_type ASC";
$recipe_type = mysql_query($query_recipe_type,$dbconn) or die(mysql_error());
$ctr = 0;
While( $Row2 = mysql_fetch_array($recipe_type) ) {
echo "sub_select.options[$ctr] = new Option(\"$Row2[recipe_type]\");\n";
echo "sub_select.options[$ctr].value = \"$Row2[recipe_type]\";\n";
$ctr++;
}
?>
}
<?PHP
}
mysql_close($dbconn);
?>
}
-->
</SCRIPT>
</HEAD>
<BODY onload="BodyLoad();">
<FORM name="FormName" method="POST" action="">
<TABLE border="1">
<TR>
<TD>Main Category</TD>
<TD>Sub Category</TD>
</TR>
<TR>
<TD>
<SELECT name="occasion_type" onchange="Fill_Sub();"></SELECT>
</TD>
<TD>
<SELECT name="recipe_type" onChange="window.location=document.FormName.recipe_type.options[document.FormName.recipe_type.selectedIndex].value">
</SELECT>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
Thanks for the help.