如何在输入中传递多个值?

时间:2014-09-26 02:37:34

标签: php html forms

什么是单选按钮的好替代品?因为我需要将超过1的值传递给php页面。

<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'>
                <tr class="row_submit">
                    <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 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>

这是我的代码,我需要传递$ payment的值,这个值略有不同但是预定义。

所以例如我需要按下,LBC $运营商是LBC,$ $是BPI。

所以当我点击表格时,什么是单选按钮的一个很好的替代品,我还添加了一个jquery,当按下该行时会自动提交它。

2 个答案:

答案 0 :(得分:0)

我不确定我是否会按照你的问题解决,但是当你通过逻辑提交表单时,你能用php解决这个问题吗?

if($_POST['carrier'] == 'LBC'){
    //then payment has to be BPI correct?
}

在我看来,您有多个付款选项。

如果您需要在表单上输入第二个输入,以便在点击LBC广播时显示付款方式,您可以使用jquery进行设置。

<input type="hidden" name="payment" value=""/>

然后在jquery

$('input[name=carrier]').click(function(){
    if ($(this).is(':checked')){
        $('input[name=payment]').val('BPI');
    }
});

答案 1 :(得分:0)

如果您要发送的其他值是预定义的,您可能需要使用隐藏字段并在选择时使用javascript填充隐藏字段

e.g。

<input type="hidden" name="payment" value="" />

并在你的jQuery中(你不需要jquery,但你提到了它)

$(document).ready(function() {
    $(input:radio[name=shipping]).change(function(){
        if ($(input:radio[name=shipping]).val() === 'X') { 
            $(input:radio[name=payment]).val('Y');
        }
    })
}