0

Can I ask on how to attack this function (total score - par score). But it's tricky because if a hole hasn't been played the par should not be subtracted from current score. Here's what I've tried so far with hidden fields:

$("#scorecard").change(function() {
    var totalscore = 0;
    $("#scorecard input:hidden").each(

    function() {
        totalscore += parseInt($(this).val())
    });
    $("#score").val(totalscore * -1);
}).change();

http://jsfiddle.net/hireconor/DDfbf/11/

Conor
  • 168
  • 9
  • [`parseInt($(this).val(),10)`](http://stackoverflow.com/q/5600366/901048) – Blazemonger Apr 12 '13 at 14:08
  • 1
    You have multiple form elements with identical IDs (such as ``). This is a no-no -- IDs must be unique, and JavaScript will assume they are. Instead, give them a common class or, in the case of radio buttons, a common name which you can select as `$('[name=par01]')` – Blazemonger Apr 12 '13 at 14:15
  • javascript will not assume ID's are unique, but will just give back the first it find's in DOM. – Ol Sen Apr 12 '13 at 14:22

0 Answers0