Menu
I have 240 rows(r) of 9(c) text boxes each, I use JavaScript to store 30 rows as a page variable to keep loading time down.
The textboxes I need calculated consists of one of the 9 textbox per row (c7)
textbox_r1_c7 – (thru) – textbox_r240_c7
total =
I want to use onkeyup and make the calculation instantaneous once its entered
[code=html]<html>
<head>
<title>JavaScript Calcualtion</title>
<style type="text/css" media="screen">
.page{
display: none;
}
</style>
<script type="text/javascript">
var currentLayer = 'page1';
function showLayer(lyr) {
hideLayer(currentLayer);
document.getElementById(lyr)
.style.display = 'block';
currentLayer = lyr;
}
function hideLayer(lyr) {
document.getElementById(lyr).
style.display = 'none';
}
function showValues(form) {
var values = '';
var len = form.length - 1;
//Leave off Submit Button
for(i=0; i<len; i++) {
if (form[i].id.indexOf("C") != -1 ||
form[i].id.indexOf("B") != -1)
//Skip Continue and Back Buttons
continue;
values += form[i].id;
values += ': ';
values += form[i].value;
values += 'n';
}
alert(values);
}
</script>
</head>
<body>
<form enctype="multipart/form-data" name="form0" method="POST" action="javascript:void(0)" onSubmit="showValues(this)">
<br><br><br><br><br>
<table align="center">
<tr>
<td>
<div id="page1" class="page" style="display: block;">
<p>Page 1</p>
1: <input type="text" name="textbox_r1_c7" id="textbox_r1_c7" size="3" value="0"><br>
2: <input type="text" name="textbox_r2_c7" id="textbox_r2_c7" size="3" value="0"><br>
3: <input type="text" name="textbox_r3_c7" id="textbox_r3_c7" size="3" value="0"><br>
4: <input type="text" name="textbox_r4_c7" id="textbox_r4_c7" size="3" value="0"><br>
5: <input type="text" name="textbox_r5_c7" id="textbox_r5_c7" size="3" value="0"><br>
<p><input type="button" id="C1" value="Continue" onClick="showLayer('page2')"></p>
</div>
<div id="page2" class="page">
<p>Page 2</p>
6: <input type="text" name="textbox_r6_c7" id="textbox_r6_c7" size="3" value="0"><br>
7: <input type="text" name="textbox_r7_c7" id="textbox_r7_c7" size="3" value="0"><br>
8: <input type="text" name="textbox_r8_c7" id="textbox_r8_c7" size="3" value="0"><br>
9: <input type="text" name="textbox_r9_c7" id="textbox_r9_c7" size="3" value="0"><br>
10: <input type="text" name="textbox_r10_c7" id="textbox_r10_c7" size="3" value="0"><br>
<p><input type="button" id="B1" value="Go Back" onClick="showLayer('page1')"><input type="submit" value="Submit"></p>
</div>
</td>
</tr>
<tr>
<td>
Total: <input type="text id="total" name="total">
</td>
</tr>
</table>
</body>
</html>[/code]
[CODE] function Calc(){
var frm = document.form0;
var total=0;
if (!frm.ary) frm.ary=[frm.textbox_r1_c7];
for (var xyz=0;xyz<frm.ary.length;xyz++){
if (frm.ary[xyz].value.length>0&&!isNaN(frm.ary[xyz].value)) total+=frm.ary[xyz].value*1;
}
frm.suba1.value=total;
}[/CODE]
[code=html]<html>
<head>
<title>JavaScript Calcualtion</title>
<style type="text/css" media="screen">
.page{
display: none;
}
</style>
<script type="text/javascript">
var currentLayer = 'page1';
function showLayer(lyr) {
hideLayer(currentLayer);
document.getElementById(lyr)
.style.display = 'block';
currentLayer = lyr;
}
function hideLayer(lyr) {
document.getElementById(lyr).
style.display = 'none';
}
function showValues(form) {
var values = '';
var len = form.length - 1;
//Leave off Submit Button
for(i=0; i<len; i++) {
if (form[i].id.indexOf("C") != -1 ||
form[i].id.indexOf("B") != -1)
//Skip Continue and Back Buttons
continue;
values += form[i].id;
values += ': ';
values += form[i].value;
values += 'n';
}
alert(values);
}
function Calc(x) {
var theForm = x.form;
var total = 0;
//var available = parseInt(theForm.Available.value); // assuming you do not need to update that
for (var i=0;i<theForm.elements.length;i++) {
if (theForm.elements[i].name=='textbox_r[]_c7') {
var val = parseInt(theForm.elements[i].value,10);
total+=(isNaN(val))?0:val;
}
}
theForm.totalmins.value = total;
//theForm.totalqa.value = available-total;
}
window.onload=function() { // handle retuning to this page
var mins = document.forms[0].elements['textbox_r[]_c7']; // assuming the FIRST [0] form
if (mins.length) Calc(mins[0]);
else Calc(mins);
}
</script>
</head>
<body>
<form enctype="multipart/form-data" name="form0" id="form0" method="POST" action="javascript:void(0)" onSubmit="showValues(this)">
<br><br><br><br><br>
<table align="center" id="table1">
<tr>
<td>
<div id="page1" class="page" style="display: block;">
<p>Page 1</p>
1: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
2: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
3: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
4: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
5: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
<p><input type="button" id="C1" value="Continue" onClick="showLayer('page2')"></p>
</div>
<div id="page2" class="page">
<p>Page 2</p>
6: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
7: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
8: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
9: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
10: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
<p><input type="button" id="C1" value="Continue" onClick="showLayer('page3')"><input type="button" id="B1" value="Go Back" onClick="showLayer('page1')"></p>
</div>
<div id="page3" class="page">
<p>Page 3</p>
11: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
12: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
13: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
14: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
15: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
<p><input type="button" id="C1" value="Continue" onClick="showLayer('page4')"><input type="button" id="B1" value="Go Back" onClick="showLayer('page2')"></p>
</div>
<div id="page4" class="page">
<p>Page 4</p>
16: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
17: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
18: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
19: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
20: <input type="text" name="textbox_r[]_c7" id="textbox_r[]_c7" size="3" value="0" onKeyUp="Calc(this)"><br>
<p><input type="button" id="B1" value="Go Back" onClick="showLayer('page3')"><input type="submit" value="Submit"></p>
</div>
</td>
</tr>
<tr>
<td>
Total: <input type="text id="totalmins" name="totalmins">
</td>
</tr>
</table>
</form>
</body>
</html>[/code]
0.1.9 — BETA 6.17