2012-10-21 49 views
1

我有一个PHP文件,它有一个表单和2个提交按钮,onclick的1个按钮它必须通过从下拉列表中选择的值。它不会将值传递给接受POST数据的php文件。但是,如果我只有一个按钮和相同的形式,这工作正常。 我在下面找到我的代码。两个提交按钮和1个表单不传递值

<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","[email protected]#"); 
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();' /> &nbsp;&nbsp;&nbsp; <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> &nbsp;&nbsp; &nbsp;&nbsp; <a href='invoice-edit.php' target='_parent'> <input name='Edit' type='button' value='Edit !'></a> &nbsp;&nbsp; <a href='invoice-cancel.php' target='_parent'><input name='Edit' type='button' value='Cancel !'></a> &nbsp;&nbsp; <a href='index.htm' target='_parent'><input name='Close' type='button' value='CLOSE !'></a><br></center> 
</center> 

</body> 
</html> 
+0

您的 “提交” 按钮打印和PRINT2? – Mate

+0

@mate是的,是否应该更改名称以提交两个按钮? – user1114409

+0

@Mate我试图改变按钮名称提交,它不起作用 – user1114409

回答

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");' /> &nbsp;&nbsp;&nbsp; 
             <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> &nbsp;&nbsp; &nbsp;&nbsp; <a href='invoice-edit.php' target='_parent'> <input name='Edit' type='button' value='Edit !'></a> &nbsp;&nbsp; <a href='invoice-cancel.php' target='_parent'><input name='Edit' type='button' value='Cancel !'></a> &nbsp;&nbsp; <a href='index.htm' target='_parent'><input name='Close' type='button' value='CLOSE !'></a><br></center> 
           </center> 

           </body> 
           </html> 
+0

谢谢伙伴,这工作正常! – user1114409

+1

太棒了!始终为名称变量分配一个更适合您的名称,供您以及将来需要使用该代码的任何人使用; – Mate

+0

当然会这么做!非常感谢,它节省了大量的时间! – user1114409