0

I am having a bit of trouble figuring out how to pass the selected radio button value thru JQUERY and ultimately to php.

The following is the html markup:

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

Then I am attempting to pass the data thru jquery so it can be caught via php. This is my present jquery markup:

        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()
        };

When I review the passing in Chrome's developer tools, the donation field/s are not being passed at all.

Could someone explain what I am missing with this? I have tried various ways of passing the donation value, but to no avail.

Thank you!

7
  • 4
    First of all, it's invalid to have multiple elements with the same id Commented Apr 17, 2015 at 20:12
  • That's the easy way out. Commented Apr 17, 2015 at 20:14
  • You're not actually posting data. You are just putting the values into variable. Check out this api.jquery.com/jquery.ajax. Also this seems like you should just form submit the data. Why do you want to do this with Jquery? Commented Apr 17, 2015 at 20:18
  • because of the wonderful effects that can be done with jquery Commented Apr 17, 2015 at 20:20
  • Possible dupe: stackoverflow.com/questions/22400490/… Commented Apr 17, 2015 at 20:25

1 Answer 1

1

For those who research and come across this post, the proper answer to my question is to detect the value that has been checked by doing this:

'donation'  : $('input[name=donation]:checked').val(),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.