• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

html/javascript form question

BearX00

Senior member
Okay here is my problem
I have a table of input boxes located in a form
right now... the horizontal values of the form are dynamically added with the on change function and computed into a total at the end of a row. so this way i keep a total of the row and it updates automatically.
now my problem is i want to do the same thing for the columns and i cant get the BOTH to work onchange. i can get one or the other but not both of them to work correctly. if anyone knows how to do this id much appreciate the help.
 
Hey, Bear. Post your COMPLETE code. Let all of us have a look see. If you are lucky 😀
perphaps someone will get it working for ya!
 
<tr>
<td></td>
<td><input type=&quot;text&quot; name=&quot;monHrs13&quot; size=&quot;6&quot; maxlength=&quot;6&quot; oldvalue=&quot;0&quot;
onblur=&quot;if (!(isANumber(this.value, 1))) {this.focus();}&quot;
onchange=&quot;this.form.totHrs13.value=computeTotal( this, hidTot13 )&quot;></td>
<td><input type=&quot;text&quot; name=&quot;tueHrs13&quot; size=&quot;6&quot; maxlength=&quot;6&quot; oldvalue=&quot;0&quot;
onblur=&quot;if (!(isANumber(this.value, 1))) {this.focus();}&quot;
onchange=&quot;this.form.totHrs13.value=computeTotal( this, hidTot13 )&quot;></td>
<td><input type=&quot;text&quot; name=&quot;wedHrs13&quot; size=&quot;6&quot; maxlength=&quot;6&quot; oldvalue=&quot;0&quot;
onblur=&quot;if (!(isANumber(this.value, 1))) {this.focus();}&quot;
onchange=&quot;this.form.totHrs13.value=computeTotal( this, hidTot13 )&quot;></td>
<td><input type=&quot;text&quot; name=&quot;thuHrs13&quot; size=&quot;6&quot; maxlength=&quot;6&quot; oldvalue=&quot;0&quot;
onblur=&quot;if (!(isANumber(this.value, 1))) {this.focus();}&quot;
onchange=&quot;this.form.totHrs13.value=computeTotal( this, hidTot13 )&quot;></td>
<td><input type=&quot;text&quot; name=&quot;friHrs13&quot; size=&quot;6&quot; maxlength=&quot;6&quot; oldvalue=&quot;0&quot;
onblur=&quot;if (!(isANumber(this.value, 1))) {this.focus();}&quot;
onchange=&quot;this.form.totHrs13.value=computeTotal( this, hidTot13 )&quot;></td>
<td><input type=&quot;text&quot; name=&quot;satHrs13&quot; size=&quot;6&quot; maxlength=&quot;6&quot; oldvalue=&quot;0&quot;
onblur=&quot;if (!(isANumber(this.value, 1))) {this.focus();}&quot;
onchange=&quot;this.form.totHrs13.value=computeTotal( this, hidTot13 )&quot;></td>
<td><input type=&quot;text&quot; name=&quot;sunHrs13&quot; size=&quot;6&quot; maxlength=&quot;6&quot; oldvalue=&quot;0&quot;
onblur=&quot;if (!(isANumber(this.value, 1))) {this.focus();}&quot;
onchange=&quot;this.form.totHrs13.value=computeTotal( this, hidTot13 )&quot;></td>
<td><input type=&quot;text&quot; name=&quot;totHrs13&quot; size=&quot;10&quot; maxlength=&quot;10&quot; value=&quot;0&quot;
readonly ><input type=&quot;hidden&quot; name=&quot;hidTot13&quot; value=0></td>
<td><input type=&quot;text&quot; name=Sick value=&quot;00534 | Sick/Personal&quot; size=20 readonly ></td>
</tr>

<tr>
<td><input type=&quot;text&quot; name=&quot;totHrs14&quot; size=&quot;10&quot; maxlength=&quot;10&quot; value=&quot;0&quot;
readonly ><input type=&quot;hidden&quot; name=&quot;hidTot14&quot; value=0> </td>
<td><input type=button name=calcTot value=&quot;Calculate Total&quot; onclick=&quot;this.form.totHrs14.value=TotalForm( this, hidTot14 )&quot; >
</tr>

<script type=&quot;text/javascript&quot;>
function isANumber(number, alrt) {
answer = 1;
period = 0;


//the first digit was numeric, so check the rest
for (var i=0; i<number.length; i++ ){
curChar = number.charAt(i);
if( curChar == &quot;.&quot; ){
if( period == 1 ){
answer = 0;
if( alrt == 1 ){
alert(&quot;Please enter a numeric value\n&quot;
+ &quot;in the form of: <number>.<number>&quot; );
}
break;
}
period = 1;
}
else if (( curChar != &quot;0&quot😉 &amp;&amp; (!parseFloat(curChar)) ) {
answer = 0;
if( alrt == 1 ){
alert(&quot;Please enter a numeric value\n&quot;
+ &quot;in the form of: <number>.<number>&quot; );
}
break;
}

}

return answer;
}

function computeTotal( field, hidTot ){
with( field.form ){

hidTot.value = eval( hidTot.value ) - eval( field.oldvalue );
if( field.value == &quot;&quot; ){
field.oldvalue = 0;
}
else if( isANumber( field.value, 0 ) != 1 ){
field.oldvalue = 0;
}
else{
field.oldvalue = eval( field.value );
hidTot.value = eval( hidTot.value ) + eval( field.value );
}

return( hidTot.value );
}
}

function TotalForm( field, hidTot){

hidTot.value = eval( field.form.totHrs01.value ) + eval( field.form.totHrs02.value ) + eval(
field.form.totHrs03.value ) + eval( field.form.totHrs04.value )
+ eval( field.form.totHrs05.value ) + eval( field.form.totHrs06.value ) + eval(
field.form.totHrs07.value ) +
eval( field.form.totHrs08.value ) + eval( field.form.totHrs09.value ) + eval(
field.form.totHrs10.value ) +
eval( field.form.totHrs11.value ) + eval( field.form.totHrs12.value ) + eval(
field.form.totHrs13.value );
return( hidTot.value );

}
</script>

This is the basic structure of my code. there are multiple rows formatted the same way as the above one.. the functions are fairly simple but basically each row gets its total calculated automatically and the column only gets totaled when you click hte button. i tried a call to the function that does the column total inside the row total function and it almost worked but it screwed with some things so i cant have that. if anyone can give me a simple solution. please do so. thanks
 
Back
Top