Hi all,
I have this script here;
*************************************
<HTML>
<HEAD>
<TITLE></TITLE>
<script language="JavaScript">
__uid = 0;
template = [{"width":"","prefix":"Descr","size":35},
{"width":"","prefix":"Amount","size":5}];
doc = document;
function addRowTo(id) {
var tbl = doc.getElementById(id);
// create a new row
var newrow = doc.createElement("TR"
var newcol , newinput;
for (var i in template) {
newcol = doc.createElement("TD"
newcol.width = template["width"];
newinput = doc.createElement("INPUT"
newinput.name = template["prefix"]+__uid;
newinput.size = template["size"];
newcol.appendChild(newinput);
newrow.appendChild(newcol);
}
tbl.appendChild(newrow);
newrow.cells[template.length-1].firstChild.onblur=function(){addRowTo('tbl1body')};
newrow.cells[0].firstChild.focus();
__uid++;
}
</script>
</HEAD>
<body onLoad="addRowTo('tbl1body')">
<form name="mainform" method="POST" action="">
<table id="tbl1">
<tbody id="tbl1body">
<tr align=right><td><B>Total :</B><INPUT TYPE="text" size=8 NAME="PortTotal" ID = "PortTotal" readonly value="0" style="background-color:#FFFFFF;border-style:solid;border-width:0;border-color:;"> </td></tr>
<tr><td><B>Description</B></td><td><B>Amount</B></td></tr>
</tbody>
</table>
<!-- <button onclick="addRowTo('tbl1body');">Add Row >></button> -->
<input id="submit" type="submit" name="save" value="Save">
</form>
</BODY>
</HTML>
*************************************************
What it does is that I enter a description and an amount and when "tab" another row is added in order to repeat the process.
Now what I am trying to acheive without success is that everytime I hit tab and that a new row is added I need to cumulate the values entered in the second field and display it in the field call "total". So if in the first row I enter 20 in the amount field when a new row is added the value 20 must be displayed in the total field, if I enter 30 in the second row than when hit tab the value 50 must appear in the total field, and so on...
I really do not know how to acheive this and I've tried severals things...
I know I also have a field validation to ensure that it's only numeric that is entered in the field value, but this is not my problem currently.. so let's simply assume that we are always entering numbers in there. I will put my validation after.
Any help would be more than greatly appreciated.
Thanks alot
Greetings
I have this script here;
*************************************
<HTML>
<HEAD>
<TITLE></TITLE>
<script language="JavaScript">
__uid = 0;
template = [{"width":"","prefix":"Descr","size":35},
{"width":"","prefix":"Amount","size":5}];
doc = document;
function addRowTo(id) {
var tbl = doc.getElementById(id);
// create a new row
var newrow = doc.createElement("TR"
var newcol , newinput;
for (var i in template) {
newcol = doc.createElement("TD"
newcol.width = template["width"];
newinput = doc.createElement("INPUT"
newinput.name = template["prefix"]+__uid;
newinput.size = template["size"];
newcol.appendChild(newinput);
newrow.appendChild(newcol);
}
tbl.appendChild(newrow);
newrow.cells[template.length-1].firstChild.onblur=function(){addRowTo('tbl1body')};
newrow.cells[0].firstChild.focus();
__uid++;
}
</script>
</HEAD>
<body onLoad="addRowTo('tbl1body')">
<form name="mainform" method="POST" action="">
<table id="tbl1">
<tbody id="tbl1body">
<tr align=right><td><B>Total :</B><INPUT TYPE="text" size=8 NAME="PortTotal" ID = "PortTotal" readonly value="0" style="background-color:#FFFFFF;border-style:solid;border-width:0;border-color:;"> </td></tr>
<tr><td><B>Description</B></td><td><B>Amount</B></td></tr>
</tbody>
</table>
<!-- <button onclick="addRowTo('tbl1body');">Add Row >></button> -->
<input id="submit" type="submit" name="save" value="Save">
</form>
</BODY>
</HTML>
*************************************************
What it does is that I enter a description and an amount and when "tab" another row is added in order to repeat the process.
Now what I am trying to acheive without success is that everytime I hit tab and that a new row is added I need to cumulate the values entered in the second field and display it in the field call "total". So if in the first row I enter 20 in the amount field when a new row is added the value 20 must be displayed in the total field, if I enter 30 in the second row than when hit tab the value 50 must appear in the total field, and so on...
I really do not know how to acheive this and I've tried severals things...
I know I also have a field validation to ensure that it's only numeric that is entered in the field value, but this is not my problem currently.. so let's simply assume that we are always entering numbers in there. I will put my validation after.
Any help would be more than greatly appreciated.
Thanks alot
Greetings