views:

39

answers:

1

Hi i want to get radiobutton value using jquery. This is the radiobutton code. The period[count] naming is because the radiobutton is loop in array using javascript

<input type='radio' name='period["+count+"]' value='1' checked/>Full<input type='radio' name='period["+count+"]' value='0.5'/>Half (AM)<input type='radio' name='period["+count+"]' value='0.5'/>Half (PM)

Question is how do i get the total value of the checked radio button?I try this code but it give only the first value of checked radio button

var values2 = $("input:radio[name='period[2]']").val();
var values3 = $("input:radio[name='period[3]']").val();

Edited

This is the code to solve this problem thanks to Aaron Saunders

var x = 0;
    $("input:radio[name^='period']:checked").each(function(){
    x = x + parseFloat($(this).val());
    });
+1  A: 

find all that start with period, then add them up

var x = 0;
$("input:radio[name^='period']").each(function{
        x = x + this.val();
     });
Aaron Saunders
hi thanks for the code, however it have some syntax error. I have corrected it and now my problem solve. See the edited part. Thanks again!
cyberfly
yeah i just typed it up, sorry i did not really test it
Aaron Saunders