2015-04-17 62 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(),