I have this javascript code that decided that it didn't want to work
anymore. At one point in time it did work. I don't remember changing
anything that would have caused it to stop working. But anyway, below
is the JavaScript code that is in a .js file:
by the way, the error is:
Error: 'elements[...].value' is null or not an object
function calcIt(name,thisForm,num) {
var num = (!num) ? 5 : num;
var val = 0 * 1;
var tot = name + "T";
var lcv = (!num) ? 1*1 : 0;
for (var i = lcv; i <= num; i++) {
var elem = name + i;
//This is where the error occurs
var qty = thisForm.elements[elem].value * 1;
if ( isNaN(qty) )
qty = 0;
if (qty < 0) {
alert("You cannot have a negative number");
thisForm.elements[elem].value = 0;
break;
}
val += qty;
}
thisForm.elements[tot].value = val;
}
And here is the HTML that's calling this function:
<input type="text" name="draft<%=i%>" size=2 maxlength=11
class="Normal" onChange="calcIt('draft',this.form);"></td>
<input type="text" name="final<%=i%>" size=2 maxlength=11
class="Normal" onChange="calcIt('final',this.form);"></td>
<input type="text" name="rep<%=i%>" size=2 maxlength=11 class="Normal"
onChange="calcIt('rep',this.form);"></td>
Any help would be appreciated.
Thanks,
- Jeremy