-3

I have used html and javascript code from this post at my test website.

I want to change radio button from second group to checkbox, where user can select multiple option from group 2 and it should add one value of radio button selected from group 1 and one or more values selected through checkboxes in group two, but it is adding only one values of check box. Please check my test URL to understand the issues. Also I want to place Paypal code for payment for total sum, where I should place that. If I want to have three groups in future, then what to do. Please take some time for this. I am new to JavaScript.

Community
  • 1
  • 1
abhishek
  • 13
  • 6

2 Answers2

1
$('#b1').click(function () {
var total = 0;
$("input[type=radio]:checked").each(function () {
    total += parseFloat($(this).val());
});
$('input[type="checkbox"]:checked').each(function () {
     total += parseFloat($(this).val());
});
$("#totalSum").val(total);

});

0

DEMO

$('#b1').click(function () {
    var total = 0;
    $("input[type=radio]:checked").each(function () {
        total += parseFloat($(this).val());
    });
    $('input[type="checkbox"]:checked').each(function () {
         total += parseFloat($(this).val());
    });
    $("#totalSum").val(total);
});

DEMO

$('input[type="checkbox"],input[type=radio]').change(function () {
    var total = 0;
    $("input[type=radio]:checked").each(function () {
        total += parseFloat($(this).val());
    });
    $('input[type="checkbox"]:checked').each(function () {
         total += parseFloat($(this).val());
    });
    $("#totalSum").val(total);
});
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
  • Thanks for the solution, I have updated the HTML code here http://www.sandyalert.com/sample-page/ and script in header.php before inside but it is not working and in demo it is perfect. can you help what may be issue. If needed I can give my admin detail. – abhishek Aug 08 '13 at 11:57
  • I tried here also http://www.newspotlive.com/calc.html where earlier code was working and even in Dreamweaver earlier code is working, but this code for 2nd demo is not working any where. Is there any setup for this? or HOw should I place this code because I have placed this in same way like earlier code. @tushargupta – abhishek Aug 08 '13 at 12:43
  • @abhishek you should only one version of jQuery in http://www.newspotlive.com/calc.html . Multiple version create conflicts and check console for errors. – Tushar Gupta - curioustushar Aug 09 '13 at 03:56
  • @tusharGuptaI tried removing the other version, even I am creating a separate html file with these codes it is not working and I am testing with other codes, then it is working in html file. Is there anything else I can try. Can test it in your local by saving in a html file. – abhishek Aug 09 '13 at 10:10
  • Hi, for everyone else, who may come here for the solution. You need to add: – abhishek Aug 09 '13 at 14:35