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).
- <form id="addnew"><input type="hidden" name="clientid" value="1" />
- <table class="clientareatable" align="center" cellspacing="1">
- <tr class="clientareatableactive">
- <td>This is a test question 1</td>
- <td>
- <input class="star" type="radio" name="rating-1" value="1" title="Worst"/>
- <input class="star" type="radio" name="rating-1" value="2" title="Bad"/>
- <input class="star" type="radio" name="rating-1" value="3" title="OK"/>
- <input class="star" type="radio" name="rating-1" value="4" title="Good"/>
- <input class="star" type="radio" name="rating-1" value="5" title="Best"/>
- </td>
- </tr>
- <tr class="clientareatableactive">
- <td>This is test question 2</td>
- <td>
- <input class="star" type="radio" name="rating-2" value="1" title="Worst"/>
- <input class="star" type="radio" name="rating-2" value="2" title="Bad"/>
- <input class="star" type="radio" name="rating-2" value="3" title="OK"/>
- <input class="star" type="radio" name="rating-2" value="4" title="Good"/>
- <input class="star" type="radio" name="rating-2" value="5" title="Best"/>
- </td>
- </tr>
- <tr class="clientareatableactive">
- <td>Please describe your experience with us</td>
- <td align="left">
- <textarea id="comment" name="comment" rows="10" cols="50"></textarea>
- <br />
- <div id="charlimitinfo"> </div>
- </table>
- <br />
- <p align="center"><input id="addnewsubmit" type="submit" value="Submit!" /></p>
- </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)
- $(document).ready(function() {
- $('#addnewsubmit').click(function () {
- var $inputs = $('#addnew :input');
- var data = "_a=add";
- $inputs.each(function() {
- data = data+'&'+this.name+'='+$(this).val();
- });
- $('#addnewsubmit').attr('disabled', 'disabled');
- $.ajax({
- url: "/testimonials.php",
- type: "GET",
- data: data,
- cache: false,
- success: function (html) {
- $('#results').html(html);
- }
- });
- return false;
- });
- });
Any help with this would be greatly appreciated. Thanks!
--Frank