"Abby Lee" <ab*******@hotmail.com> wrote in message
news:ui***************************@news.ks.uiuc.ed u...
Can someone tell me what is wrong with this statement?
function subtotal(){
var ttot = 1;
for (var i = 1; i < 7; i++){
if(isPosInt(document.forms[0].total(i).value)){
ttot += document.forms[0].total(i).value;
}
document.forms[0].subtot.value = format(ttot);
}
}
I know the "isPosInt" function works because it works for other things and
Mike wrote it...so I did not add it.
And I do have a global varible elsewhere var e =
document.forms[0].elements, but I also can't get "if(isPosInt(ea['total' + i].value))" to work
Will this help? Watch for word-wrap.
<html>
<head>
<title>subtotal.htm</title>
<script type="text/javascript">
function subtotal() {
var ttot = 0;
for (var i=0; i<7; i++) {
var temp = document.forms[0].total(i).value;
if (isPosInt(temp)) {
ttot += parseInt(temp,10);
}
}
document.forms[0].subtot.value = format(ttot);
}
function isPosInt() {
// your code here!
return true;
}
function format(what) {
// your code here!
return what;
}
</script>
<style type="text/css">
..numb { text-align:right }
</style>
</head>
<body>
<form>
<br><input type="text" name="total" size="5" value="1" class="numb">
<br><input type="text" name="total" size="5" value="2" class="numb">
<br><input type="text" name="total" size="5" value="3" class="numb">
<br><input type="text" name="total" size="5" value="4" class="numb">
<br><input type="text" name="total" size="5" value="5" class="numb">
<br><input type="text" name="total" size="5" value="6" class="numb">
<br><input type="text" name="total" size="5" value="7" class="numb">
<br>=======
<br><input type="text" name="subtot" size="5" value="" class="numb">
<br><input type="button" value="Total!" onclick="subtotal()">
</form>
</body>
</html>
Obviously you should remove the values for all "total" fields.