Tuesday, 10 September 2013

Sum of checkboxes values and number boxes

Sum of checkboxes values and number boxes

I am having trouble trying that this script sums, on the one hand, the
values of all the marked checkboxes (all with name="PV". The sum should be
"PV1"), and on the other hand, the values manually written in the relevant
input number boxes (all with name="pvo". The sum should be PV2). After
that, with those values it should calculate other numbers (PB1 and PB2).
However it doesn't return anything. What am I doing wrong?
<script language="JavaScript" type="text/javascript">
var PV = document.getElementsByName("PV")
var PVO = document.getElementsByName("pvo")
var PV1 = document.getElementById("PV1")
var PV2 = document.getElementById("PV2")
var PB1 = document.getElementById("PB1")
var PB2 = document.getElementById("PB2")
function clickCh(form){calcpv(this.form) ; caclpvo(this.form) ;
calculate(this.form)}
function trunc(n){return ~~n; }
function calcpv(form){for(i=0 ; i < PV.length ; i++)
{if(PV[i].checked == true) {PV1.value += Number(PV[i].value)} }}
function calcpvo(form){for(i=0 ; i < PVO.length ; i++)
{PV2.value += Number(PVO[i].value=)} }
function calculate(form){if(PV1>PV2){PB1.value = trunc(10 + (PV1.value*1 -
PV2.value*1 -1)/150)}
else {PB1.value = trunc(10 + (PV1.value*1 - PV2.value*1 +1)/150)};
PB2.value = 20 - PB1.value
}
</script>
A relevant sample of my HTML code (there are many table rows similar to
this one)
<td><input type="checkbox" name="PV" value=70>
<input type="checkbox" name="PV" value=70>
<input type="checkbox" name="PV" value=70>
<input type="checkbox" name="PV" value=70></td>
<td><input type="text"></td><td><input type="number" name="pvo"></td></tr>
<input id="PV1" type="text" name="" readonly="readonly">
<input id="PV2" type="text" name="" readonly="readonly">
<input type="button" onclick="clickCh(this.form)" value="calcular"><br>
<input id="PB1" type="text" name="" readonly="readonly">
<input id="PB2" type="text" name="" readonly="readonly"><br>

No comments:

Post a Comment