2012-10-21 79 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