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

Recommended Answers

All 9 Replies

ican't figure it out if this textbox, label or what.

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.

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">&nbsp;</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">&nbsp;</td>
                                        <td><span class="tabletitle">VAT</span></td>
                                        <td>&nbsp;</td>
                                      </tr>
                                      <tr class="dark">
                                        <td height="30" colspan="4">&nbsp;</td>
                                        <td><span class="tabletitle">Net Total </span></td>
                                        <td>&nbsp;</td>
                                      </tr>
                                    </tbody>
                                  </table>

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.

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

Hi

I have solved my issues.

Thanks for your support

I want to add multiple dynamic textboxes on button click depends on my need and there is already one text box in which value=50
So my q. is the sum of values in dynamic textboxes should not be greater than 50 if the sum = 50 then textboxses should not be added dynamicaly on button click it must show an alert message for Sum cant be greater than 50

plz give me an ans....
or mail me on pavanmali.5679@gmail.com

Member Avatar for diafol

start your own thread. Show any work you've done so far. Also describe what else you tried and what didn't work. This isn't a free code service, it's a help forum for helping you with YOUR code.

Member Avatar for diafol

Had some time to play. About 10 mins and round 50 lines of js. Not showing off, just saying it's not very difficult (beginner level) and that you should have a go yourself before asking for a complete solution: http://screencast.com/t/au5VGbkb

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.