tootallstretch
MIS
Hi,
I need this function to work with select boxes instead of text boxes. I have searched and tried for days....Eventually, the form will have many rows. Here is the code that I have:
function updateSums(row)
{
var dfe = document.forms[0].elements;
var box1 = dfe['txtcol1_'+row];
var box2 = dfe['txtcol2_'+row];
var box3 = dfe['txtcol3_'+row];
var actual1 = false;
var actual2 = false;
var val1 = box1.value;
if(val1 && !isNaN(val1))
{
val1=parseInt(val1);
actual1=true;
}
//end if
else
{
val1 = 0;
actual1=false;
}//end else
var val2 = box2.value;
if(val2 &&!isNaN(val2))
{
val2 = parseInt(val2);
actual2 = true;
}//end if
else
{
val2=0;
actual2=false;
}//end else
var val3 = box3.value;
var boxAll = dfe['grandTotal'];
var total = boxAll.value;
if(actual1 && actual2)
{
if(val3)
total-=val3;
val3 = val2-val1;
box3.value= val3;
if(val3 && !isNaN(val3))
{
val3=parseInt(val3);
if(total)
total = parseInt(total) + val3;
else
total = val3;
}//end if
boxAll.value = total;
}//end if
}//end updateSums(var)
</script>
<body>
<form>
<table id='sumTable'>
<td>
<input type='text' name='txtcol1_1' onblur='updateSums(1);'/> </td>
<td>
<input type='text' name='txtcol2_1' onblur='updateSums(1);'/> </td>
<td>
<input type='text' name='txtcol3_1' readonly='readonly'/>
</td>
<tr>
<td>
<input type='text' name='txtcol1_2' onblur='updateSums(2);'/> </td>
<td>
<input type='text' name='txtcol2_2' onblur='updateSums(2);'/> </td>
<td>
<input type='text' name='txtcol3_2' readonly='readonly'/>
</td>
</tr>
<tr>
<td colspan='2' align='right'>total:</td>
<td>
<input type='text' name='grandTotal' readonly='readonly'/>
</td>
</tr>
</table>
</form>
</body>
</html>
I need this function to work with select boxes instead of text boxes. I have searched and tried for days....Eventually, the form will have many rows. Here is the code that I have:
function updateSums(row)
{
var dfe = document.forms[0].elements;
var box1 = dfe['txtcol1_'+row];
var box2 = dfe['txtcol2_'+row];
var box3 = dfe['txtcol3_'+row];
var actual1 = false;
var actual2 = false;
var val1 = box1.value;
if(val1 && !isNaN(val1))
{
val1=parseInt(val1);
actual1=true;
}
//end if
else
{
val1 = 0;
actual1=false;
}//end else
var val2 = box2.value;
if(val2 &&!isNaN(val2))
{
val2 = parseInt(val2);
actual2 = true;
}//end if
else
{
val2=0;
actual2=false;
}//end else
var val3 = box3.value;
var boxAll = dfe['grandTotal'];
var total = boxAll.value;
if(actual1 && actual2)
{
if(val3)
total-=val3;
val3 = val2-val1;
box3.value= val3;
if(val3 && !isNaN(val3))
{
val3=parseInt(val3);
if(total)
total = parseInt(total) + val3;
else
total = val3;
}//end if
boxAll.value = total;
}//end if
}//end updateSums(var)
</script>
<body>
<form>
<table id='sumTable'>
<td>
<input type='text' name='txtcol1_1' onblur='updateSums(1);'/> </td>
<td>
<input type='text' name='txtcol2_1' onblur='updateSums(1);'/> </td>
<td>
<input type='text' name='txtcol3_1' readonly='readonly'/>
</td>
<tr>
<td>
<input type='text' name='txtcol1_2' onblur='updateSums(2);'/> </td>
<td>
<input type='text' name='txtcol2_2' onblur='updateSums(2);'/> </td>
<td>
<input type='text' name='txtcol3_2' readonly='readonly'/>
</td>
</tr>
<tr>
<td colspan='2' align='right'>total:</td>
<td>
<input type='text' name='grandTotal' readonly='readonly'/>
</td>
</tr>
</table>
</form>
</body>
</html>