简体   繁体   English

如何$ _POST没有点击按钮?

[英]How to $_POST without clicking button?

Before, i have a form that has a radio button and of course, it submits the value in the radio button when pressing submit. 之前,我有一个带有单选按钮的表单,当然,按下提交时它会在单选按钮中提交值。

but how do i do it if i dont want radio buttons anymore? 但如果我不再需要收音机按钮,我该怎么办呢? When pressing the table cell or row will automatically submit the value to the next page without the submit button? 当按表格单元格或行时会自动将值提交到下一页而不提交按钮?

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

how do i make it submit without using submit button or the radio button, for when i press the row, it submits the value to the next page and i go to the next page. 如何在不使用提交按钮或单选按钮的情况下进行提交,因为当我按下行时,它会将值提交到下一页,然后我转到下一页。

thank you 谢谢

EDIT. 编辑。

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

Just use the rows to submit it. 只需使用行提交即可。 Consider this markup: 考虑这个标记:

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

Then on your JS: 然后在你的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>

Then on PHP: 然后在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;
}

Try this one: 试试这个:

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

I wish it works! 我希望它有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 点击按钮后开机自检 - POST when clicking button 单击提交按钮后如何在文本框下方发布评论? - how to post comment below the text box after clicking submit button? 如何在不单击提交按钮的情况下提交页面加载表单? - How to submit a form on page load without clicking submit button? 如何刷新表而不再单击我的按钮 - How to refresh a table without clicking again on my button 如何在不单击jQuery Mobile中的任何按钮的情况下选择数据 - How to select data without clicking on any button in jquery mobile 如何在不单击搜索按钮的情况下创建搜索功能? - how to create a search feature without clicking the search button? 通过单击添加评论按钮,它仅适用于第一篇文章。 我该如何处理那堵墙的所有帖子 - by clicking add comment button it works for the first post only. how can i do this for all post in that wall 单击提交按钮时无法发布/错误 - Cannot POST / error when clicking Submit button 如何在不使用 GET 数据中的数据刷新页面而不单击按钮的情况下显示 mysql 数据库 - How to display a mysql database without refreshing the page with data from GET data without clicking button PHP-如何通过单击上一页按钮而不刷新页面来显示POST详细说明结果 - PHP - How to show POST elaboration result clicking previous page button and not refreshing page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM