Checkbox javascript problem lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- _Julia_ · 2015-01-24 17:29 Hello, i'm making this code and i m trying to create code that can count the checkboxes together. for now i have writen this code : not important verbs are in my language so ignore that .. i m looking for any ideas how can i change this code to be able to count both checkboxes for now i can only pick one and when i do both my reasults came wrong ... it counts only 1.  so i would be glad if anyone could help me with that. so my question is how to rewrite the code to be able to count both checkboxes into the result. thanks { if there are more then 2 then ofc it have to count all of them. } A simple frameset document    

Dan z prijmu fyzickych osob

   
   hruby prijem:
       
   uhrn pojist. zaplaceneho zamesttnavatelem za zamestnance:
       
   odecitatelne polozky slevy:
       
   manzelka manzel v domacnosti:
       
   studium:
       
   dite:
       
   
    ---------------------------------------------------------------------- skalogryz · 2015-01-24 18:49 instead of assigning the value to "z" variable, you should increase its value, just replace Code: [Select]  z=typ.value; with Code: [Select]  z+=typ.value; ---------------------------------------------------------------------- _Julia_ · 2015-01-27 21:28 well i tried but the code it's still not working right the same problem that it counts only the 1 possibility.  i tryed everything but i cant find anything in pure javascript that do that ... blew ---------------------------------------------------------------------- TurboRascal · 2015-01-27 22:00 Isn't this forum a strange place to come for help about javascript? ---------------------------------------------------------------------- skalogryz · 2015-01-27 22:19 Quote from: _Julia_ on January 27, 2015, 10:28:50 pmwell i tried but the code it's still not working right the same problem that it counts only the 1 possibility.  Your loop is correct, but elements of "typ"-array are misused. This is how it should be. Code: [Select]   var z = 0;    for (var i = 0; i < typ.length; i++) {         if (typ[i].type === 'checkbox' && typ[i].checked) {         z += parseInt(typ[i].value);          } note: that value is now wrapped into parseInt. Otherwise you'd see an unexpected 1050, instead of 60 as value of "z" ---------------------------------------------------------------------- skalogryz · 2015-01-27 22:20 Quote from: TurboRascal on January 27, 2015, 11:00:15 pmIsn't this forum a strange place to come for help about javascript?  well... isn't it "Programming / Network and Web Programming" sub section ?