2015-04-17 22 views
0

我有点麻烦搞清楚如何通过JQUERY将选定的单选按钮值传递给PHP。jquery传递单选按钮阵列

以下是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的开发者工具的传球,捐赠场/ s的并不是在所有的通过。

有人可以解释我缺少这个吗?我尝试了各种方式来传递捐赠价值,但无济于事。

谢谢!

+4

首先,它是无效的有多个元素相同的ID – LcSalazar

+0

这是简单的出路。 – MrTechie

+0

你实际上并没有发布数据。你只是把值变成可变的。看看这个http://api.jquery.com/jquery.ajax/。此外,这似乎你应该只是提交数据。你为什么想用JQuery来做到这一点? – mattfetz

回答

1

对于那些谁研究和碰到过这样的帖子,正确回答我的问题是检测已通过做这个检查值:

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