dynamic row table option problem

A

Azik

Hello, I have one question
i created table and in this table i added some another options
for ex at the previous table there were only one problem sum of the
dynamically added rows
in this beside sum i need to sum of the percent of this sum
for ex 10% of this dynamically added rows
for ex. i added ten rows and i entered different values into these
rows. in front of each row there are different option of percent
selection.
in row1 i added 1000 and chose from drop down box 10%
in row2 i added 2500 and chose from drop down box 30%
..............................................................
and so on
and finally i summed separately sum of the values and sum percentage
of this values to other texbox value
if possible help me
thanks beforehands
here is code



<html><head><title>dinamik sheet</title>

<script>
function addrow(){

var tbl=document.getElementById('sheet');
var lastrow=tbl.rows.length;
var iteration=lastrow;
var row=tbl.insertRow(lastrow);
var cellLeft=row.insertCell(0);
var textNode=document.createTextNode(iteration);
cellLeft.appendChild(textNode);
var cellRight=row.insertCell(1);
var el=document.createElement('input');
el.type='text';
el.name='txtRow'+iteration;
el.size=40;
el.setAttribute('sumMe',"1");
cellRight.appendChild(el);

var cellRight2=row.insertCell(2);
var el1=document.createElement('input');
el1.type='text';
el1.name='txtRowe'+iteration;
el1.size=40;
el1.setAttribute('sumMe',"1");
cellRight2.appendChild(el1);





var cellRightsel=row.insertCell(3);
var sel=document.createElement('select');
sel.name='selRow'+iteration;
sel.options[0]=new Option('10%','value0');
sel.options[1]=new Option('20%','value1');
sel.options[2]=new Option('30%','value2');
cellRightsel.appendChild(sel);
var cellRightsel2=row.insertCell(4);
var sel1=document.createElement('input');
sel1.type='button';
sel1.value='sum row'+iteration;
sel1.name='button'+iteration;
cellRightsel2.appendChild(sel1);
}
</script>
<script>
function sum(){
var form=document.getElementById('eval_edit');
if(!form) return;
var fields=form.getElementsByTagName('input');
var s=0;
for (var i=0;i<fields.length;i++){

if( fields.getAttribute('sumMe') != "1" ) continue;//reject
any field not carring the "sumMe" attribute
var txt = fields.value;
if(txt != ( '' + Number(txt) )) continue;//reject non-numeric
entries
s += Number(txt);
}
if(form['total']){ form['total'].value = s; }
}

onload = function(){
sum();
}

</script>
</head>
<body>
<form name="eval_edit" method="POST">
<table align="center" width="75%">
<tr>
<td align="center">Balance sheet</td></tr>
<tr><td align="center">
<table border="1" id="sheet"><tr><td>object</td><td>Income</td><td>Tax
from income</td><td>instruktor</td></tr>
</td><td><input sumMe="1" type="text" name="txtrowe" id="txtrowe"
size="40"/></td>
<td><select name="selRow0">
<option value="value0">10%</option>
<option value="value1">20%</option>
<option value="value2">30%</option></select></td><td><input
type="button" name="button1" value="sum row1" id="button1"></tr></
table>
INCOME SUM<input name="total" type="text"/>
<input type="button" value="Add" onclick="addrow()" />
<input type="button" value="Remove" onclick="removeRow()" />
<input type="button" value="SUM" onClick="sum()"/>
<input type="submit" value="Submit" /> <input name="taxtotal"
type="text"/>Tax SUM with desirable percent for ex: 20%
</td>
</tr>
</table>
</form>

</body>

</html>
 
S

SAM

Le 9/26/09 9:26 AM, Azik a écrit :
Hello, I have one question
i created table and in this table i added some another options
for ex at the previous table there were only one problem sum of the
dynamically added rows
in this beside sum i need to sum of the percent of this sum
for ex 10% of this dynamically added rows
for ex. i added ten rows and i entered different values into these
rows. in front of each row there are different option of percent
selection.
in row1 i added 1000 and chose from drop down box 10%
in row2 i added 2500 and chose from drop down box 30%
.............................................................
and so on
and finally i summed separately sum of the values and sum percentage
of this values to other texbox value
if possible help me
thanks beforehands
here is code

doctype missing
<html><head><title>dinamik sheet</title>

<script>

function addrow(){

a little bit complicationned ...

var tbl=document.getElementById('sheet');
var lastrow=tbl.rows.length;
var iteration=lastrow;
var row=tbl.insertRow(lastrow);

var c = function (el) {
var cell = row.insertCell(idx);
cell.appendChild(el);
idx++;
}
var idx = 0;

var el = document.createTextNode(iteration);
c(el);

el = document.createElement('input');
el.name = 'txtRow'+iteration;
el.size = '40';
c(el);

el = document.createElement('input');
el.name = 'txtRowe'+iteration;
el.size = '40';
c(el);

el = document.createElement('select');
el.name = 'selRow'+iteration;
el.options[0] = new Option('10%','1.1');
el.options[1] = new Option('20%','1.2');
el.options[2] = new Option('30%','1.3');
c(el);

el = document.createElement('input');
el.type = 'button';
el.value = 'sum row'+iteration;
el.onclick = sum; // variante: = function(){sub(this);};
c(el);
}
function sum(){


function sum(){
var f = document.getElementById?
document.getElementById('eval_edit') :
document.forms[0];
if(f) {
var n = f.length,
sum = f[n-6],
tax = f[n-1],
sl;
sum.value = '';
tax.value = '';
for(var i=0, q = n-6; q>i; i+=4) {
sl = f[i+2];
sl = 10 +sl.selectedIndex*10;
f[i+1].value = f.value * sl /100;
sum.value = sum.value*1 + f.value*1;
tax.value = tax.value*1 + f[i+1].value*1;
}
}
}

function sub( what) {
what = what.parentNode;
while(what.tagName != 'tr') what = what.parentNode;
var sl = what.getElemenstByTagName('select')[0];
sl = 10 + sl.selectedIndex *10;
what = what.getElementsByTagName('input');
what[1].value = what[0].value * sl /100;
}

onload = function(){
sum();
}

window.onload = sum;
</script>
</head>
<body>
<form name="eval_edit" method="POST">

And the ID ? where is the ID ?

<table align="center" width="75%">
<tr>
<td align="center">Balance sheet</td></tr>
<tr><td align="center">
<table border="1" id="sheet"><tr><td>object</td><td>Income</td><td>Tax
from income</td><td>instruktor</td></tr>
<tr><td>1</td>
<td><input sumMe="1" type="text" name="txtrow1" id="txtrow1" size="40"/>

No need of : />
(only to use if we are in XHTML)

<input name="txtrow1" id="txtrow1" size="40">

is OK
(depends of the doctype, 'size' can be forbidden)

</td><td><input sumMe="1" type="text" name="txtrowe" id="txtrowe"
size="40"/></td>
<td><select name="selRow0">
<option value="value0">10%</option>
<option value="value1">20%</option>
<option value="value2">30%</option></select></td>
<td><input type="button" name="button1" value="sum row1" id="button1"></tr>

<td><input name="button1" value="sum row1" onclick="sum()"></td>
</tr>

variante :

<td><input name="button1" value="sum row1" onclick="sub(this)"></td>
 
S

SAM

Le 9/26/09 4:53 PM, SAM a écrit :
<td><input name="button1" value="sum row1" onclick="sum()"></td>
</tr>

Please read :

<td><input type="button" value="sum row1" onclick="sum()"></td>
</tr>

variante :

<td><input type="button" value="sum row1" onclick="sub(this)"></td>
</tr>

(no need of 'name' or 'id' for this button, but 'type' yes!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top