jquery传递单选按钮数组

时间:2015-04-17 20:10:31

标签: javascript php jquery

我在确定如何通过JQUERY传递所选单选按钮值并最终传递给php时遇到了一些麻烦。

以下是html标记:

    <li class="gchoice_1_14_0">
        <input name="donation[]" type="radio" value="25" id="donation" tabindex="14">
        <label for="choice_1_14_0" id="label_1_14_0">$25</label>
    </li>

    <li class="gchoice_1_14_1">
        <input name="donation[]" type="radio" value="50" id="donation" tabindex="15">
        <label for="choice_1_14_1" id="label_1_14_1">$50</label>
    </li>

    <li class="gchoice_1_14_2">
        <input name="donation[]" type="radio" value="100" id="donation" tabindex="16">
        <label for="choice_1_14_2" id="label_1_14_2">$100</label>
    </li>

    <li class="gchoice_1_14_3">
        <input name="donation[]" type="radio" value="350" id="donation" tabindex="17">
        <label for="choice_1_14_3" id="label_1_14_3">$350 - Guardian Angel Sponsorship – a donation at this level provides interview and follow-up services for one child</label>
    </li>

    <li class="gchoice_1_14_4">
        <input name="donationother" type="radio" value="other_amount" id="donation" tabindex="18" onfocus="jQuery(this).next('input').focus();">
        <input id="donation_other" name="donation_other" type="text" value="" onfocus="jQuery(this).prev(&quot;input&quot;).attr(&quot;checked&quot;, true); if(jQuery(this).val() == &quot;Other&quot;) { jQuery(this).val(&quot;&quot;); }" onblur="if(jQuery(this).val().replace(&quot; &quot;, &quot;&quot;) == &quot;&quot;) { jQuery(this).val(&quot;Other&quot;); }" tabindex="18">
    </li>

然后我试图通过jquery传递数据,以便它可以通过php捕获。这是我目前的jquery标记:

        post_data = {
            'user_name'     : $('input[name=full_name]').val(), 
            'user_email'    : $('input[name=email]').val(), 
            'address'   : $('input[name=address]').val(), 
            'address2'  : $('input[name=address2]').val(), 
            'city'  : $('input[name=city]').val(), 
            'state' : $('input[name=state]').val(), 
            'zip'   : $('input[name=zip]').val(), 
            'ccnum' : $('input[name=ccnum]').val(), 
            'expmonth'  : $('select[name=expmonth]').val(), 
            'expyear'   : $('select[name=expyear]').val(), 
            'cardname'  : $('input[name=cardname]').val(),
            'ccvcode'   : $('input[name=ccvcode]').val(),
            'donation'  : $('input[name=donation]').val(),
            'donation_other'    : $('input[name=donation_other]').val(),
            'phone_number'  : $('input[name=phone2]').val(), 
            'subject'       : $('select[name=subject]').val(), 
            'msg'           : $('textarea[name=message]').val()
        };

当我查看传入Chrome的开发者工具时,捐赠字段根本没有被传递。

有人可以解释我对此缺少的内容吗?我尝试了各种传递捐赠价值的方法,但无济于事。

谢谢!

1 个答案:

答案 0 :(得分:1)

对于那些研究和看过这篇文章的人来说,我的问题的正确答案是通过这样做来检测已经检查过的值:

'donation'  : $('input[name=donation]:checked').val(),