I'd do it this way
Code:
var numCats = 8;
function checkData(o) {
if (/^[1-5]$/.test(o.value)) {
return true;
doTotal(o.form);
}
else {
alert("Must be a number between 1 and 5!");
o.select();
o.focus();
return false;
}
}
function doTotal(f) {
var total = 0;
for (var i=1, i<=numCats ; i++) {
var o = f.elements['cat'+i];
total += (/^\s*$/.test(o.value)) ? 0 : parseInt(o.value);
}
f.totalpoints.value = total;
}
<input type="text" name="cat1" id="cat1" onBlur="return checkData(this)" />
<!-- Etc etc -->
<input type="text" name="cat1" id="cat8" onBlur="return checkData(this)" />
<input type="text" name="totalpoints" id="totalpoints" />
Bookmarks