Total for Dynamic Text box Hi Friends.
i am working on my internal work. i am having n dynamic rows, Each and every row contain total.
i want to sum all the rows total.
i have attached the screen shot for the reference
Attachments
rpv_sen
Posting Whiz in Training
204 posts since Mar 2011
Reputation Points: 24
Solved Threads: 18
Skill Endorsements: 0
ican't figure it out if this textbox, label or what.
masterjiraya
Posting Whiz
322 posts since Jul 2008
Reputation Points: 10
Solved Threads: 31
Skill Endorsements: 4
Use javascript or jQuery to add every rows totalrate value and show it in a total value. Providing some code may help to fix ur problem.
paulrajj
Junior Poster
102 posts since Mar 2010
Reputation Points: 17
Solved Threads: 38
Skill Endorsements: 0
Hi
i have posted my script, i have written script for multiplication. but i need script for sum of total_rate in GrandTotal
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th width="6%" height="30" align="center"><span class="tabletitle">S.No</span></th>
<th width="44%"><span class="tabletitle">Description</span></th>
<th width="13%"><span class="tabletitle">UOM</span></th>
<th width="11%"><span class="tabletitle">Qty</span></th>
<th height="30"><span class="tabletitle">Rate</span></th>
<th width="16%"><span class="tabletitle">Total Rate</span></th>
</tr>
</thead>
<tbody>
<?php
$create_po1 = $_POST['create_po'];
$mat_po = $_POST['material_id'];
$limit2 = count($create_po1);
$j=1;
for($k=0;$k<$limit2;$k++)
{
$create_po1[$k] = mysql_real_escape_string($create_po1[$k]);
$c_po = $create_po1[$k];
$mat_po1 = $mat_po[$k];
$qr = "select * from material_indent_req where id='$c_po' and status='Approved'";
//echo $qr;
$qres = mysql_query($qr,$conn);
while($qrow = mysql_fetch_array($qres))
{
$qindent_no = $qrow['indent_no'];
$qmat = $qrow['material_subcat_code'];
$qmatname = $qrow['material_subcat_name'];
$qsite = "select *,count(po_no),sum(required_qty) from material_po where indent_no='$qrow[indent_no]' and material_id='$qmat'";
//echo $qsite;
$qrsite = mysql_query($qsite,$conn);
$qmsite = mysql_fetch_array($qrsite);
$req_ty = $qmsite['sum(required_qty)'];
$site = $qrow['sitename'];
$count_po = $qmsite['count(indent_no)'] + 1;
$pending_qty = $qrow['required_qty'] - $req_ty;
?>
<tr class="light">
<td height="30" align="center"><span class="logintitle"><?php echo $j;?></span></td>
<td><span class="logintitle"><?php echo $qmatname;?></span></td>
<td><span class="logintitle"><?php echo $qrow['unit'];?></span></td>
<td><input name="required_qty[]" type="text" class="inputline" id="required_qty<?php echo $j;?>" value="<?php echo $pending_qty;?>" size="12" /></td>
<td width="10%"><input name="rate[]" type="text" class="inputline" id="rate<?php echo $j; ?>" onchange="multiply(<?php echo $j; ?>)" size="12"/></td>
<td><input name="total_rate[]" type="text" class="inputline" id="total_rate<?php echo $j; ?>" size="18" readonly="readonly"/></td>
</tr>
<?php $j++; } } ?>
<tr class="dark">
<td height="30" colspan="4"> </td>
<td><span class="tabletitle">Total </span></td>
<td><input name="GrandTotal" type="text" class="inputline" id="GrandTotal" size="20" readonly="readonly"/></td>
</tr>
<tr class="light">
<td height="30" colspan="4"> </td>
<td><span class="tabletitle">VAT</span></td>
<td> </td>
</tr>
<tr class="dark">
<td height="30" colspan="4"> </td>
<td><span class="tabletitle">Net Total </span></td>
<td> </td>
</tr>
</tbody>
</table>
rpv_sen
Posting Whiz in Training
204 posts since Mar 2011
Reputation Points: 24
Solved Threads: 18
Skill Endorsements: 0
At some point, unclear in your code, you are multiplying qty x rate for each item, so $item_total = qty x rate; although, I do not see this in your code here. anyway I am assuming this is happening in your while loop as you are doing each item. so prior to your while loop make a new variable $grand_total = 0;
inside your while loop after $item_total is calculated do this:
$grand_total += $item_total; // <-- wherever $item_total comes from.
// when you want to display it, $grand_total should hold the values of all items.
ddymacek
Posting Whiz
324 posts since Jun 2010
Reputation Points: 38
Solved Threads: 68
Skill Endorsements: 0
Hi
Thanks for your reply.
i have done the multiplication through Java script the code is below
<script type=text/javascript>
function multiply(id){
var a;
var b;
var c;
a = document.getElementById("rate" + id).value;
b = document.getElementById("required_qty" + id).value;
c = a * b
document.getElementById("total_rate" + id).value = Math.round(c*100)/100;
}
function getSum(){
var val=document.getElementById("total_rate" + id).value;
var sum=0;
for(var j=0;j<val.id;j++){
val=parseInt(val[j].value);
sum +=val;
}
alert("total is ="+sum);
// str+="<span><input type='text' value="sum" /></span>";
}
</script> and i am trying to find out sum through getsum function as above.
Help me
rpv_sen
Posting Whiz in Training
204 posts since Mar 2011
Reputation Points: 24
Solved Threads: 18
Skill Endorsements: 0
Hi
I have solved my issues.
Thanks for your support
rpv_sen
Posting Whiz in Training
204 posts since Mar 2011
Reputation Points: 24
Solved Threads: 18
Skill Endorsements: 0
Question Answered as of 1 Year Ago by
masterjiraya ,
paulrajj
and
ddymacek