我正在创建一个具有许多动态下拉列表的表单。在第一个下拉列表中选择的值被传递给下一个,并基于该值查询被触发到数据库,下一个下拉列表中填充了数据。这个过程在这里进行了四次。 .
为了获取在下拉列表中选择的值,我使用了 javascript 函数来提交表单,保持我的表单操作为空白..
现在,当我获得所有值时,我必须将此信息保存到数据库中,因为我需要将这些值传递给下一个表单,但由于我的表单操作为空白,它只会重新加载页面...
<?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>