php - 如何在不单击按钮的情况下 $_POST?

标签 php jquery html forms

以前,我有一个带有单选按钮的表单,当然,它会在按下提交时提交单选按钮中的值。

但是如果我不再需要单选按钮,我该怎么做呢?当按下表格单元格或行时会自动将值提交到下一页而无需提交按钮?

<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>

最佳答案

只需使用行提交即可。考虑这个标记:

<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;
}

关于php - 如何在不单击按钮的情况下 $_POST?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26050422/

相关文章:

javascript - 如何删除图像按钮周围的输入字段?

php - 如何通过表单标签将数据发送到另一个页面?

php - iframe 根据 javascript 和 php 变化

javascript - jQuery/JavaScript 替换损坏的图像

php - 在 html 页面上显示 php 结果

javascript - jQuery off().remove() 或 .remove().off() 性能

javascript - Jquery:需要帮助理解为什么它同时隐藏和显示列表元素,我在脚本中自相矛盾吗?

javascript - 获取围绕特定元素引用的文本

css - 如何解决中间垂直液体盒的问题

css - 两个 Div,相同的 CSS,相同的行