我有一个php文件,其中有一个表单和2个提交按钮,单击1个按钮,它必须传递从下拉列表中选择的值。它没有将值传递给接受POST数据的php文件。但是,如果我只有一个按钮和相同的表单,这工作正常。 Pl在下面找到我的代码。
<html>
<head>
<title>Invoice Printing</title>
<script type="text/javascript">
function showlink()
{
window.open('invoiceprint2.php');
}
function showlink3()
{
window.open('invoiceprint3.php');
}
</script>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#026465">
<tr>
<td><div align="center"><span class="style1"> Amogh Gases Private Ltd <br></span>
<center class="style5">INVOICE PRINTING</center>
<br><br>
<br>
</td>
</tr>
</table>
<!--------------VALIDATIONS ------------------->
<br>
<br>
<form name="form1" method="post" action="" target="_blank">
<table width='40%' height='39' border='0' cellpadding='2' cellspacing='0' align='center'>
<tr>
<td class='sty1'><div align='left'>Please select Invoice No. to PRINT: <br>
<br>
You can choose more than one invoice number from the options, by holding CTRL key on your keyboard and select the numbers.</div></td>
<td>
<?php
$con = mysql_connect("localhost","tech1","te!@#");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("tech1", $con);
$result = mysql_query("SELECT Invno FROM INVHDR", $con);
echo "<select multiple='multiple' size='20' name='invnos[]'>";
while($nt=mysql_fetch_assoc($result))
{//Array or records stored in $nt
echo "<option value=$nt[Invno]>$nt[Invno]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
mysql_close($con);
?>
</td>
</tr>
</table><br>
<center><input name="PRINT" type="button" value="PRINT Invoice to Laser Printer!" onClick='showlink();' /> <input name="PRINT2" type="button" value="PRINT Invoice to Dotmatrix Printer !" onClick='showlink3();'/>
</form>
<br><br><br><br>
<a href='frameinvoice.php' target='_parent'><input name='Add' type='button' value='Add'></a> <a href='invoice-edit.php' target='_parent'> <input name='Edit' type='button' value='Edit !'></a> <a href='invoice-cancel.php' target='_parent'><input name='Edit' type='button' value='Cancel !'></a> <a href='index.htm' target='_parent'><input name='Close' type='button' value='CLOSE !'></a><br></center>
</center>
</body>
</html>
答案 0 :(得分:0)
<html>
<head>
<title>Invoice Printing</title>
<script type="text/javascript">
function postData(someValueToEvalute)
{
switch(someValueToEvalute){
case "1":{
document.forms[0].action = 'invoiceprint2.php'
break;
}
case "2":{
document.forms[0].action = 'invoiceprint3.php'
break;
}
default: { alert('fail');}
}
document.forms[0].submit();
}
</script>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#026465">
<tr>
<td><div align="center"><span class="style1"> Amogh Gases Private Ltd <br></span>
<center class="style5">INVOICE PRINTING</center>
<br><br>
<br>
</td>
</tr>
</table>
<!--------------VALIDATIONS ------------------->
<br>
<br>
<form name="form1" method="post" action="" target="_blank">
<!-- PHP CODE REMOVED!!!!! -->
<center>
<input name="PRINT" type="button" value="PRINT Invoice to Laser Printer!" onClick='postData("1");' />
<input name="PRINT2" type="button" value="PRINT Invoice to Dotmatrix Printer !" onClick='postData("2");'/>
</form>
<br><br><br><br>
<a href='frameinvoice.php' target='_parent'><input name='Add' type='button' value='Add'></a> <a href='invoice-edit.php' target='_parent'> <input name='Edit' type='button' value='Edit !'></a> <a href='invoice-cancel.php' target='_parent'><input name='Edit' type='button' value='Cancel !'></a> <a href='index.htm' target='_parent'><input name='Close' type='button' value='CLOSE !'></a><br></center>
</center>
</body>
</html>