problem with dynamic table rows sum

problem with dynamic table rows sum

Page 1 of 1

2 Replies - 2071 Views - Last Post: 29 September 2009 - 12:54 AM

#1 azegurb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-September 09

problem with dynamic table rows sum

Post icon  Posted 27 September 2009 - 05:52 AM

I have created dynamic table with two columns
for ex:first column is Income column
and second column is tax from Income
at the third column are different percent options
for ex. I wrote first column 1000 and chose from third drop down box 10%
I would like when i chose 10% sum function automatically writes 10% percent of 1000 into second column so that 100
here is code if possible pls help me i really need this code and i bellieve that this code is useful both me and other users
thanks beforehand




 <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");
el.onblur=sum;
 
 
cellRight.appendChild(el);
 
var cellRight2=row.insertCell(2);
var el1=document.createElement('input');
el1.type='text';
el1.name='txtRowe'+iteration;
el1.id='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%','value="10"');
sel.options[1]=new Option('20%','value="20"');
sel.options[2]=new Option('30%','value="30"');
cellRightsel.appendChild(sel);
var cellRightsel2=row.insertCell(4);
 
}
</script>
<script> 
function sum(){	
var form=document.getElementById('eval_edit');
	if(!form) return;
	var s1 = 0;
	var s2 = 0;
	var tbl=document.getElementById('sheet');
	var iteration=tbl.rows.length-1;
	for(var i=1; i<=iteration; i++){
		var el = form['txtRow'+i];
		if(!el) continue;
		var txt = el.value;
		if(txt != ( '' + Number(txt) )) continue;//reject non-numeric entries
		var el2 = form['selRow'+i];
		var el3 = document.getElementById('txtRowe'+i);
		if(!el2 || !el3) alert('Error in calculating totals');
		var percent = Number(el2[el2.selectedIndex].value)/100;
		var tax = Number(txt) * percent;
		el3.innerHTML = tax.toFixed(2);
 
		s1 += Number(txt);
		s2 += tax;
	}
	if(form['total']){ form['total'].value = s1.toFixed(2); }
	if(form['taxtotal']){ form['taxtotal'].value = s2.toFixed(2); }
}
 
 
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>
<tr><td>1</td>
<td><input sumMe="1" type="text" name="txtrow1" id="txtrow1" size="40"/></td><td><input sumMe="1" type="text" name="txtrowe" id="txtrowe" size="40"/></td>
<td><select name="selRow0">
<option value="value="10">10%</option>
<option value="value="20">20%</option>
<option value="value="30">30%</option></select></td></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>	  


Is This A Good Question/Topic? 0
  • +

Replies To: problem with dynamic table rows sum

#2 crazyjugglerdrummer  Icon User is offline

  • GAME OVER. NERD WINS.
  • member icon

Reputation: 119
  • View blog
  • Posts: 690
  • Joined: 07-January 09

Re: problem with dynamic table rows sum

Posted 28 September 2009 - 07:41 AM

Add an onselectionchanged event to the select box being changed and that will fill the appropriate td with the computation :D
Was This Post Helpful? 1
  • +
  • -

#3 azegurb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-September 09

Re: problem with dynamic table rows sum

Posted 29 September 2009 - 12:54 AM

View Postcrazyjugglerdrummer, on 28 Sep, 2009 - 06:41 AM, said:

Add an onselectionchanged event to the select box being changed and that will fill the appropriate td with the computation :D

Hi

if possible can you help me
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1