How to sum radio button values using either Javascript or jQuery?
I would do it like that:
function calcscore(){
var score = 0;
$(".calc:checked").each(function(){
score+=parseInt($(this).val(),10);
});
$("input[name=sum]").val(score)
}
$().ready(function(){
$(".calc").change(function(){
calcscore()
});
});
See this js fiddle example
the html structure is equal to yours, only i added a class calc
, so that i can selected them easier.