I am creating a form which has many dynamic dropdown..
values selected in first dropdown is passed to next and based on that value query is fired to the database and the next dropdown is filled with the data.. this process goes four time here..
for getting the value selected in the dropdown i have used javascript function for form submitting keeping my form action blank..
now when i get all the values i have to save this information to the database for that i need to pass these values to the next form but as my form action is blank it just reloads the page…
<?php
include('config.php');
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
function showproduct(product_name)
{
document.frm.submit();
}
</script>
<script language="javascript" type="text/javascript">
function showpacking(batch_no)
{
document.frm.submit();
}
</script>
<script language="javascript" type="text/javascript">
function showprice(packing)
{
document.frm.submit();
}
</script>
</head>
<body>
<form action="" method="post" name="frm" id="frm">
<table width="500" border="0">
<tr>
<td width="119">Product Name</td>
<td width="371">
<select name="product_name" id="product_name" onChange="showproduct(this.value);">
<option value="">--Select--</option>
<?php
$sql1="select distinct product_name from fertilizer";
$sql_row1=mysql_query($sql1);
while($sql_res1=mysql_fetch_assoc($sql_row1))
{
?>
<option value="<?php echo $sql_res1["product_name"]; ?>" <?php if($sql_res1["product_name"]==$_REQUEST["product_name"]) { echo "Selected"; } ?>><?php echo $sql_res1["product_name"]; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Batch No</td>
<td id="batch">
<select name="batch_no" id="batch_no" onChange="showpacking(this.value);">
<option value="">--Select--</option>
<?php
$sql="select distinct batch_no from fertilizer where product_name='$_REQUEST[product_name]'";
$sql_row=mysql_query($sql);
while($sql_res=mysql_fetch_assoc($sql_row))
{
?>
<option value="<?php echo $sql_res["batch_no"]; ?>" <?php if($sql_res["batch_no"]==$_REQUEST["batch_no"]) { echo "Selected"; } ?>><?php echo $sql_res["batch_no"]; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Packing</td>
<td id="packing">
<select name="packing" id="packing" onChange="showprice(this.value);">
<option value="">--Select--</option>
<?php
$sql2="select distinct packing from fertilizer where product_name='$_REQUEST[product_name]' and batch_no='$_REQUEST[batch_no]'";
$sql_row=mysql_query($sql2);
while($sql_res2=mysql_fetch_assoc($sql_row))
{
?>
<option value="<?php echo $sql_res2["packing"]; ?>" <?php if($sql_res2["packing"]==$_REQUEST["packing"]) { echo "Selected"; } ?>><?php echo $sql_res2["packing"]; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>price per unit</td>
<td id="price">
<?php
$sql3="select distinct rate_per_unit from fertilizer where product_name='$_REQUEST[product_name]' and batch_no='$_REQUEST[batch_no]' and packing=$_REQUEST[packing]";
$sql_row=mysql_query($sql3);
while($sql_res3=mysql_fetch_assoc($sql_row))
{
?>
<input type="text "name="price" id="price" value="<?php echo $sql_res3["rate_per_unit"]; ?>" >
<?php
}
?>
</td>
</tr>
<tr>
<td>
<input type="submit" name="Save" value="save">
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
Replace
with something like: