Suppose we had a function that looked like this:
<SCRIPT language="JavaScript">
function totalyear(_year){
document.forms["tippage"].pTotal1.value =
parseFloat(document.forms["tippage"].pLocal1.value) +
parseFloat(document.forms["tippage"].pState1.value) +
parseFloat(document.forms["tippage"].pFed11.value) +
parseFloat(document.forms["tippage"].pFed12.value) +
parseFloat(document.forms["tippage"].pFed13.value);
}
</script>
The variable _year is a number representing the set of values to be added. That is if _year=1 the function is good as shown. However, if _year=2, we want the function to add different controls as in:
<SCRIPT language="JavaScript">
function totalyear(_year){
document.forms["tippage"].pTotal2.value =
parseFloat(document.forms["tippage"].pLocal2.value) +
parseFloat(document.forms["tippage"].pState2.value) +
parseFloat(document.forms["tippage"].pFed21.value) +
parseFloat(document.forms["tippage"].pFed22.value) +
parseFloat(document.forms["tippage"].pFed23.value);
}
</script>
So the question is, How would you revise the function to incorporate the _year value into the controls specification?
Thanks
<SCRIPT language="JavaScript">
function totalyear(_year){
document.forms["tippage"].pTotal1.value =
parseFloat(document.forms["tippage"].pLocal1.value) +
parseFloat(document.forms["tippage"].pState1.value) +
parseFloat(document.forms["tippage"].pFed11.value) +
parseFloat(document.forms["tippage"].pFed12.value) +
parseFloat(document.forms["tippage"].pFed13.value);
}
</script>
The variable _year is a number representing the set of values to be added. That is if _year=1 the function is good as shown. However, if _year=2, we want the function to add different controls as in:
<SCRIPT language="JavaScript">
function totalyear(_year){
document.forms["tippage"].pTotal2.value =
parseFloat(document.forms["tippage"].pLocal2.value) +
parseFloat(document.forms["tippage"].pState2.value) +
parseFloat(document.forms["tippage"].pFed21.value) +
parseFloat(document.forms["tippage"].pFed22.value) +
parseFloat(document.forms["tippage"].pFed23.value);
}
</script>
So the question is, How would you revise the function to incorporate the _year value into the controls specification?
Thanks