Hi Anakadote,
Sorry! Maybe I didn't explain myself very well.
The cascading dropdowns depend on the form being re-submitted: So if a selection is made from Select1, the autoSubmit() function is called and the contents of Select 2 are updated. However, calling autoSubmit() reloads the form and causes the form data to be POSTED and the INSERT Query (i've commented this query - it's right at the bottom of the code) to be run with each form reload.
Here is the complete code:
<html>
<body>
<h2> Start Lot </h2>
<?php
require_once('mysqli_connect.php');
$sl = $sn = $st = null; //declare vars
if(isset($_POST["silicon_lot"]) && is_numeric($_POST["silicon_lot"]))
{
$sl = $_POST["silicon_lot"];
}
if(isset($_POST["silicon_wafer_number"]) && is_numeric($_POST
["silicon_wafer_number"]))
{
$sn = $_POST["silicon_wafer_number"];
}
if(isset($_POST["silicon_type"]) && is_numeric($_POST["silicon_type"]))
{
$st = $_POST["silicon_type"];
}
?>
<h3> Enter Silicon Details </h3>
<script language="JavaScript">
// The following function is called as part of Populating the Cascading Dropdowns
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>
<form name="theForm" method="post" action="start_fdd_lot3.php">
<table >
<tr>
<td width="70px">
FDD Lot
</td>
<td>
<input type="text" name="fdd_lot" id="fdd_lot" value="<?php if (isset($_REQUEST['fdd_lot'])) echo $_REQUEST['fdd_lot']; ?>" />
</td>
</tr>
<tr>
<td>
Comment
</td>
<td>
<input type="text" name="fdd_lot_comment" id="fdd_lot_comment" size="25" value="<?php if (isset($_REQUEST['fdd_lot_comment'])) echo $_REQUEST['fdd_lot_comment']; ?>" />
</td>
</tr>
</table>
<select name="silicon_type" id="silicon_type" onChange="document.getElementById('silicon_wafer_number').selectedIndex=0; autoSubmit();" >
<option value="null">silicon type</option>
<?php
$q1 = "SELECT silicon_type_id, silicon_type FROM tbl_silicon_type ";
$s1 = mysqli_query($dbc,$q1);
while($row = mysqli_fetch_array($s1))
{
echo ("<option value=\"$row[silicon_type_id]\" " . ($st == $row["silicon_type_id"] ? " selected" : "") . ">$row[silicon_type]</option>");
}
?>
</select>
<select name="silicon_lot" id="silicon_lot" onChange="autoSubmit();">
<option value="null">silicon lot</option>
<?php
$q2 = "SELECT silicon_lot_id, silicon_lot FROM tbl_silicon_lot WHERE (silicon_type_id = $st) ";
$s2 = mysqli_query($dbc,$q2);
while($row = mysqli_fetch_array($s2))
{
echo ("<option value=\"$row[silicon_lot_id]\" " . ($sl == $row["silicon_lot_id"] ? " selected" : "") . ">$row[silicon_lot]</option>");
}
?>
</select>
<select name="silicon_wafer_number" id="silicon_wafer_number" onChange="autoSubmit();">
<option value="null">number</option>
<?php
$q3 = "SELECT silicon_id, silicon_wafer_number, silicon_assigned FROM tbl_silicon WHERE (silicon_lot_id = $sl && silicon_assigned=0) ";
$s3 = mysqli_query($dbc,$q3);
while($row = mysqli_fetch_array($s3))
{
echo ("<option value=\"$row[silicon_id]\" " . ($sn == $row["silicon_id"] ? " selected" : "") . ">$row[silicon_wafer_number]</option>");
}
?>
</select>
<?php
$gl = $gn = $gt = null; //declare vars
if(isset($_POST["glass_lot"]) && is_numeric($_POST["glass_lot"]))
{
$gl = $_POST["glass_lot"];
}
if(isset($_POST["glass_substrate_number"]) && is_numeric($_POST["glass_substrate_number"]))
{
$gn = $_POST["glass_substrate_number"];
}
if(isset($_POST["glass_type"]) && is_numeric($_POST["glass_type"]))
{
$gt = $_POST["glass_type"];
}
?>
<br />
<h3> Enter Glass Details </h3>
<select name="glass_type" id="glass_type" onChange="document.getElementById('glass_substrate_number').selectedIndex=0; autoSubmit();" >
<option value="null">glass type</option>
<?php
$q4 = "SELECT glass_type_id, glass_type FROM tbl_glass_type ";
$s4 = mysqli_query($dbc,$q4);
while($row = mysqli_fetch_array($s4))
{
echo ("<option value=\"$row[glass_type_id]\" " . ($gt == $row["glass_type_id"] ? " selected" : "") . ">$row[glass_type]</option>");
}
?>
</select>
<select name="glass_lot" id="glass_lot" onChange="autoSubmit();">
<option value="null">glass lot</option>
<?php
$q5 = "SELECT glass_lot_id, glass_lot FROM tbl_glass_lot WHERE (glass_type_id = $gt) ";
$s5 = mysqli_query($dbc,$q5);
while($row = mysqli_fetch_array($s5))
{
echo ("<option value=\"$row[glass_lot_id]\" " . ($gl == $row["glass_lot_id"] ? " selected" : "") . ">$row[glass_lot]</option>");
}
?>
</select>
<select name="glass_substrate_number" id="glass_substrate_number" onChange="autoSubmit();">
<option value="null">number</option>
<?php
$q6 = "SELECT glass_id, glass_substrate_number, glass_assigned FROM tbl_glass WHERE (glass_lot_id = $gl && glass_assigned=0) ";
$s6 = mysqli_query($dbc,$q6);
while($row = mysqli_fetch_array($s6))
{
echo ("<option value=\"$row[glass_id]\" " . ($gn == $row["glass_id"] ? " selected" : "") . ">$row[glass_substrate_number]</option>");
}
?>
</select>
<br />
<br />
<input type="hidden" name="n1" value="<?php echo $_REQUEST["fdd_lot"];?>">
</form>
<form name="theForm2" method="post" action="start_fdd_lot3.php">
<input type="submit" name="button" id="button" value="Submit" />
<input type="hidden" name="submitted" value="TRUE" />
<script language="JavaScript">
<?php
$stype=$_REQUEST['silicon_type'];
echo ($type);
// Here is the INSERT Query that's being run every time the form is posted when
//autoSubmit() function is called. I don't know if it's possible to run this query
// outside of this form and to use the condition that all the form elements must be
// selected or have something entered into them (in the case of the text boxes)
//I've also put "xxx" below for the value as i don't know what to put in here - it's suppose to be the text entered into the fdd_lot text box above
$q1="INSERT INTO tbl_fdd_lot (fdd_lot) VALUES('xxx')";
$r = mysqli_query($dbc,$q1);
?>
</form>
</body>
</html>
Thanks