I decided to post a new thread for this one....
Thanks to khat, I have a dynamic calculator that works regardless of how may table rows with however many form fields in it:
The only thing I've really changed since I got this script was in the table I've added the column of checkboxes because what I want to do is NOT add a number to my total ("ttl") unless the corresponding "Approved" box is checked.
So, if Approved1 and Approved2 are checked, but not Approved3, then only Approved1 and Approved2 are added and calculated as "ttl."
My biggest hang up is that I don't know what you use to determine if a particular checkbox is checked or not.
Any help?
Dispensing quality rants and mishaps since 1999:
Thanks to khat, I have a dynamic calculator that works regardless of how may table rows with however many form fields in it:
Code:
<html>
<head>
<script language=javascript>
function RunningTotal(frm) {
ttl = 0;
num = 1;
moreNumbers = true;
while (moreNumbers) {
if (frm.elements["number" + num]) {
ttl += parseInt(frm.elements["number" + num].value, 10);
num++;
}
else {
moreNumbers = false;
}
}
frm.elements["total"].value = ttl;
}
</script>
</head>
<body>
<form name=blahForm>
</form>
<table width="300" border="1" cellspacing="2" cellpadding="2">
<tr>
<td> </td>
<td><input name="number1" type="text" value="10" size="5" maxlength="4" onChange="RunningTotal(this.form)"></td>
<td><input type="checkbox" name="Approve1" value="1"></td>
</tr>
<tr>
<td> </td>
<td><input name="number2" type="text" value="20" size="5" maxlength="4" onChange="RunningTotal(this.form)"></td>
<td><input type="checkbox" name="Approve2" value="1"></td>
</tr>
<tr>
<td> </td>
<td><input name="number3" type="text" value="30" size="5" maxlength="4" onChange="RunningTotal(this.form)"></td>
<td><input type="checkbox" name="Approve3" value="1"></td>
</tr>
<tr>
<td> </td>
<td><input name="number4" type="text" value="40" size="5" maxlength="4" onChange="RunningTotal(this.form)"></td>
<td><input type="checkbox" name="Approve4" value="1"></td>
</tr>
<tr>
<td> </td>
<td><input name="number5" type="text" value="50" size="5" maxlength="4" onChange="RunningTotal(this.form)"></td>
<td><input type="checkbox" name="Approve5" value="1"></td>
</tr>
<tr>
<td>Approved Total </td>
<td><input name="total" type="text" size="6" maxlength="5"></td>
<td> </td>
</tr>
</table>
</body>
</html>
The only thing I've really changed since I got this script was in the table I've added the column of checkboxes because what I want to do is NOT add a number to my total ("ttl") unless the corresponding "Approved" box is checked.
So, if Approved1 and Approved2 are checked, but not Approved3, then only Approved1 and Approved2 are added and calculated as "ttl."
My biggest hang up is that I don't know what you use to determine if a particular checkbox is checked or not.
Any help?
Dispensing quality rants and mishaps since 1999: