2014-09-26 70 views
5

之前,我有一個有單選按鈕的表單,當然,按提交時它會在單選按鈕中提交值。

但我該怎麼做,如果我不想單選按鈕了?當按下表格單元格或行時,會自動將該值提交到下一頁,而無需提交按鈕?

<form method="post" action="billing.php"> 
    <table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'> 
     <tr> 
      <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?> value="LBC"></td> 
      <td><img src="../paymentoptions/LBC.jpg" alt="LBC" class="picture"/></td> 
      <td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial. Payment method only available is through BPI Bank Deposit<p> 
       <div id='price'> Additional ₱250 </div></td> 

     </tr> 
     <tr> 
      <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?> value="PickUp"></td> 
      <td><img src="../paymentoptions/Pick-up.jpg" alt="Pick-Up" class="picture"/></td> 
      <td><p>Personally pick up your merchandise at our office. Free of Charge. Office hours: 10:00 am to 5:00 pm<p> 
       <div id='price'> Free!! </div></td> 
     </tr> 
    </table> 
</form> 

我如何提交不使用提交按鈕或單選按鈕,因爲當我按排,其提交的值到下一個頁面,我去到下一個頁面。

謝謝

編輯。

<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='centerdown'> 
    <tr> 
     <td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="BPI") echo "checked";?> value="BPI"></td> 
     <td><img src="../paymentoptions/BPI.jpg"></td> 
     <td><p>Pay by BPI bank deposit (we need confirmation of payment through email.)<p></td> 
    </tr> 

    <tr> 
     <td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="PickUp") echo "checked";?> value="PickUp"></td> 
     <td><img src="../paymentoptions/Pick-up.jpg"></td> 
     <td><p>Pick up. You have 5 days reservation period. You pay for the merchandise upon pick-up<p></td> 
    </tr> 
</table> 
+0

然後使用javascript(jquery tagged)觸發提交行點擊 – Ghost 2014-09-26 00:55:04

+0

我該怎麼做? – 2014-09-26 00:56:24

+0

[此](http://stackoverflow.com/questions/26014630/submit-form-with-jquery-by-click-on-table-cell)有幫助嗎? – ForguesR 2014-09-26 00:57:46

回答

2

只是使用行來提交它。考慮這個標記:

<form method="post" action="billing.php"> 
    <table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'> 
     <tr class="row_submit"> 
       <!-- ^^ simple class assignment --> 
      <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?> value="LBC"></td> 
      <td><img src="../paymentoptions/LBC.jpg" alt="LBC" class="picture"/></td> 
      <td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial. Payment method only available is through BPI Bank Deposit<p> 
       <div id='price'> Additional ₱250 </div></td> 

     </tr> 
     <tr class="row_submit"> 
      <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?> value="PickUp"></td> 
      <td><img src="../paymentoptions/Pick-up.jpg" alt="Pick-Up" class="picture"/></td> 
      <td><p>Personally pick up your merchandise at our office. Free of Charge. Office hours: 10:00 am to 5:00 pm<p> 
       <div id='price'> Free!! </div></td> 
     </tr> 
    </table> 
</form> 

然後在您的JS:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
    $('tr.row_submit').on('click', function(e){ 
     $('form').submit(); 
    }); 
}); 
</script> 

然後在PHP:

$info_table = array(
    'LBC' => array(
     'price' => 250, 
     'payment' => 'BPI', 
    ), 
    'PickUp' => array(
     'price' => 0, 
     'payment' => '', 
    ), 
); 

if(isset($_POST['carrier'])){ 
    echo $_POST['carrier']; 
    $price = $info_table[$_POST['carrier']]['price']; 
    $payment = $info_table[$_POST['carrier']]['payment']; 
    echo '<br/>' . $price . '<br/>'; 
    echo $payment; 
} 
+0

只是爲了澄清,因爲它似乎OP是PHP/Web新手。你應該仔細閱讀對輸入信息進行消毒,而不是直接使用$ _POST變量,否則這是正確的方法。 – DaOgre 2014-09-26 01:02:15

+2

@DaOgre如果你想準備語句,那麼當然,無論如何,這是另一個話題,它會變得太長,但我理解你的關注 – Ghost 2014-09-26 01:03:44

+0

哦,它的工作。呵呵。謝謝。嗯。如何在使用此值時放置2個值?因爲我還需要提交$ payment和$ carrier,所以不包含在代碼中。這就是爲什麼我不喜歡使用單選按鈕,因爲只有1可以提交,或者我錯了嗎?謝謝。 – 2014-09-26 01:10:31

0

試試這個:

<script type="text/javascript"> 
    function submit(){ 
     var data = $("form[action=billing.php]").serialize(); 
     $.ajax({ 
      url: "billing.php", 
      type: "POST", 
      data: data, 
      success: function(out){ 
       $(body).html(out); 
      } 
     }); 
    } 
$(document).ready(function(){ 
$('tr.row_submit').click(function(){submit();}); 
} 

</script> 

我希望它工作小號!

+0

請詳細解答您的問題。教OP去釣魚:) – dimo414 2014-09-26 04:40:26

+0

@ dimo414它選擇計費表單元素並以這種方式序列化其輸入,然後在用類'row_submit'點擊tr後通過xhr提交這個表單,最後文檔主體將被刷新形式反應 – majicson 2014-10-17 04:53:19

相關問題