How to get all checked radio button values

How to get all checked radio button values

I'm having a bit of trouble getting the checked radio values from my form so I can submit them via AJAX. The main problem is, I do not know what the name is going to be, and there could be any number of them. Here is a basic example of the HTML code (It is dynamically generated).

  1. <form id="addnew"><input type="hidden" name="clientid" value="1" />
  2.     <table class="clientareatable" align="center" cellspacing="1">
  3.         <tr class="clientareatableactive">
  4.             <td>This is a test question 1</td>
  5.             <td>
  6.                 <input class="star" type="radio" name="rating-1" value="1" title="Worst"/>
  7.                 <input class="star" type="radio" name="rating-1" value="2" title="Bad"/>
  8.                 <input class="star" type="radio" name="rating-1" value="3" title="OK"/>
  9.                 <input class="star" type="radio" name="rating-1" value="4" title="Good"/>
  10.                 <input class="star" type="radio" name="rating-1" value="5" title="Best"/>
  11.             </td>
  12.         </tr>
  13.         <tr class="clientareatableactive">
  14.             <td>This is test question 2</td>
  15.             <td>
  16.                 <input class="star" type="radio" name="rating-2" value="1" title="Worst"/>
  17.                 <input class="star" type="radio" name="rating-2" value="2" title="Bad"/>
  18.                 <input class="star" type="radio" name="rating-2" value="3" title="OK"/>
  19.                 <input class="star" type="radio" name="rating-2" value="4" title="Good"/>
  20.                 <input class="star" type="radio" name="rating-2" value="5" title="Best"/>
  21.             </td>
  22.         </tr>
  23.     <tr class="clientareatableactive">
  24.         <td>Please describe your experience with us</td>
  25.         <td align="left">
  26.             <textarea id="comment" name="comment" rows="10" cols="50"></textarea>
  27.             <br />
  28.             <div id="charlimitinfo">&nbsp;</div>
  29.     </table>
  30.     <br />
  31.     <p align="center"><input id="addnewsubmit" type="submit" value="Submit!" /></p>
  32. </form>

This main issue with this is the "rating-#" radio buttons. There could be any number of these fields (dynamically generated from a DB), so I need to make sure that all of them get submitted.

Here is the ajax code I tried, but it obviously doesn't do what I was hoping. (It appended rating-1=1, rating-1=2, rating-1=3, etc to the GET request)

  1. $(document).ready(function() {
  2.     $('#addnewsubmit').click(function () {
  3.         var $inputs = $('#addnew :input');
  4.         var data = "_a=add";
  5.         $inputs.each(function() {
  6.             data = data+'&'+this.name+'='+$(this).val();
  7.         });
  8.         $('#addnewsubmit').attr('disabled', 'disabled');
  9.         $.ajax({
  10.             url: "/testimonials.php",
  11.             type: "GET",
  12.             data: data,
  13.             cache: false,
  14.             success: function (html) {
  15.                 $('#results').html(html);
  16.             }
  17.         });
  18.         return false;
  19.     });
  20. });

Any help with this would be greatly appreciated. Thanks!

--Frank