Hi Friends

Pls help me, i have posted the code below, i am trying to multiply 2 text box values from thisqty and prate and final value has to be show in thisamt text box, and also i have attachment the screen shot

<form method="post" action="#" enctype="multipart/form-data" name="billing">
   	  <table width="1000" border="0" align="center" cellpadding="1" cellspacing="1" class="table_style1" id="billing">
  <tr>
    <th width="50" rowspan="2" bgcolor="#E4E4E4" class="table_title">S.No</th>
    <th width="125" rowspan="2" bgcolor="#E4E4E4" class="table_title">Item</th>
    <th width="100" rowspan="2" bgcolor="#E4E4E4" class="table_title">Units</th>
    <th width="91" rowspan="2" bgcolor="#E4E4E4" class="table_title">Rate</th>
    <th height="30" colspan="2" bgcolor="#E4E4E4" class="table_title">Previous Bill</th>
    <th colspan="2" bgcolor="#E4E4E4" class="table_title">This Bill</th>
    <th colspan="2" bgcolor="#E4E4E4" class="table_title">Upto Date Bill</th>
    </tr>
  <tr class="table_title">
    <th width="100" height="25" bgcolor="#E4E4E4">Qty</th>
    <th width="100" bgcolor="#E4E4E4">Amount</th>
    <th width="100" bgcolor="#E4E4E4">Qty</th>
    <th width="100" bgcolor="#E4E4E4">Amount</th>
    <th width="100" bgcolor="#E4E4E4">Qty</th>
    <th width="100" bgcolor="#E4E4E4">Amount</th>
    </tr>
  <tr>
  <br /><br />
  <?php 
		$desr="select * from billing_description where description_title='EARTH WORK & SAND FILLING'";
		//echo $desr;
	  	$r=mysql_query($desr,$conn);
	  	$i=1;
		//$item=$m["description_item"];
		while($m=mysql_fetch_array($r))
		{  
			$bitem=$m["description_item"];
			$bdata="select sum(curr_qty), sum(curr_amount) from billingdata where item='$bitem'";
			//echo $bdata;
			$bdatar=mysql_query($bdata,$conn);
			$bdatam=mysql_fetch_array($bdatar);
			
			//$pqty=$bdatam["sum(curr_qty)"];
			//echo $pqty;
			$prate = $m["description_rate"];
			//echo $prate;
			//$pamt=$pqty*$prate;
			
			$thisamt = $thisqty*$prate;
			echo $thisamt;
		?>
        
    <td class="qty"><?php echo $i; ?></td>
    <td width="250" height="30" class="textinner"><textarea name="item_1" rows="1" readonly="readonly" class="textinner" id="item_1"><?php echo $m["description_item"];?></textarea></td>
    <td class="units"><?php echo $m["description_units"];?> </td>
    <td class="rate"><input name="prate" type="text" disabled="disabled" class="prate" id="prate" value="<?php echo $prate;?>" readonly="true" /> </td>
    <td class="qty" width="100"><?php echo $bdatam["sum(curr_qty)"];?></td>
    <td class="rate" width="94"><?php echo $bdatam["sum(curr_amount)"];?></td>
    <td align="center" ><input name="thisqty" type="text" class="thisqty" id="thisqty" value="<?php echo $bdatam["thisqty"];?>" size="12" /></td>
    <td align="right"><input name="thisamt" type="text" class="thisamt" id="thisamt" value="<?php echo $thisamt; ?>" readonly="readonly";/></td>
    <td></td>
    <td></td>
    </tr>
  <?php $i++; } ?>
</table>
</form>

hi

I have to enter the number in Qty and we have to get the answer as prate*qty in Amount column

do not disabled rate text box, use readonly

remove disabled="disabled"

<td class="rate"><input name="prate" type="text"             class="prate" id="prate" value="<?php echo $prate;?>" readonly="true" /> </td>

HI

Thanks for your reply,

i have also tried your advice, but i was unable to solve it

attach your php page and mysql script for this table here

what are you expecting,

1) you want to show amount the moment user enters one qty
or
2) you want to calculate amount when user all qty, submits page, then show amount for all row

i want to show amount the moment user enters one qty

Then you need to create javascript function. and you must use on_blur even on qty textbox.

Hi have done that thing also, but i have some problem, the below are the code

<script type="text/javascript">
function line(elem) {
var a=document.getElementById("prate");
var b=document.getElementById("thisqty");
var c=a*b;
alert (c);
document.getElementById("thisamt").onblur = c;
}
</script>

<form method="post" action="#" enctype="multipart/form-data" name="billing">
   	  <table width="1000" border="0" align="center" cellpadding="1" cellspacing="1" class="table_style1" id="billing">
  <tr>
    <th width="50" rowspan="2" bgcolor="#E4E4E4" class="table_title">S.No</th>
    <th width="125" rowspan="2" bgcolor="#E4E4E4" class="table_title">Item</th>
    <th width="100" rowspan="2" bgcolor="#E4E4E4" class="table_title">Units</th>
    <th width="91" rowspan="2" bgcolor="#E4E4E4" class="table_title">Rate</th>
    <th height="30" colspan="2" bgcolor="#E4E4E4" class="table_title">Previous Bill</th>
    <th colspan="2" bgcolor="#E4E4E4" class="table_title">This Bill</th>
    <th colspan="2" bgcolor="#E4E4E4" class="table_title">Upto Date Bill</th>
    </tr>
  <tr class="table_title">
    <th width="100" height="25" bgcolor="#E4E4E4">Qty</th>
    <th width="100" bgcolor="#E4E4E4">Amount</th>
    <th width="100" bgcolor="#E4E4E4">Qty</th>
    <th width="100" bgcolor="#E4E4E4">Amount</th>
    <th width="100" bgcolor="#E4E4E4">Qty</th>
    <th width="100" bgcolor="#E4E4E4">Amount</th>
    </tr>
  <tr>
  <br /><br />
  <?php 
		$desr="select * from billing_description where description_title='EARTH WORK & SAND FILLING'";
		//echo $desr;
	  	$r=mysql_query($desr,$conn);
	  	$i=1;
		//$item=$m["description_item"];
		while($m=mysql_fetch_array($r))
		{  
			$bitem=$m["description_item"];
			$bdata="select sum(curr_qty), sum(curr_amount) from billingdata where item='$bitem'";
			//echo $bdata;
			$bdatar=mysql_query($bdata,$conn);
			$bdatam=mysql_fetch_array($bdatar);
			
			//$pqty=$bdatam["sum(curr_qty)"];
			//echo $pqty;
			$prate = $m["description_rate"];
			//echo $prate;
			//$pamt=$pqty*$prate;
			//$thisqty = $bdatam["thisqty"];
			//$thisamt = $thisqty*$prate;
			//echo $thisamt;
		?>
        
    <td class="qty"><?php echo $i; ?></td>
    <td width="250" height="30" class="textinner"><textarea name="item_1" rows="1" readonly="readonly" class="textinner" id="item_1"><?php echo $m["description_item"];?></textarea></td>
    <td class="units"><?php echo $m["description_units"];?> </td>
    <td class="rate"><input name="prate" type="text" class="prate" id="prate" value="<?php echo $prate;?>" readonly="true" /> </td>
    <td class="qty" width="100"><?php echo $bdatam["sum(curr_qty)"];?></td>
    <td class="rate" width="94"><?php echo $bdatam["sum(curr_amount)"];?></td>
    <td align="center" ><input name="thisqty" type="text" class="thisqty" id="thisqty" value="<?php echo $bdatam["thisqty"];?>" size="12" /></td>
    <td align="right"><input name="thisamt" type="text" class="thisamt" id="thisamt" value="<?php echo $thisamt; ?>" readonly="readonly" onblur="line();" /></td>
    <td></td>
    <td></td>
    </tr>
  <?php $i++; } ?>
</table>
</form>
<script type=text/javascript>
function multiply(){
a = document.getElementById('prate').value;
b = document.getElementById('thisqty').value;
c = a*b;
alert(c);
}
</script>

Note the .value

did this work?

i am getting NAN error

NaN means not a number.
One of the values is not a integer

perhaps use parseFloat

<script type=text/javascript>
function multiply(){
a = parseFloat(document.getElementById('prate').value);
b = parseFloat(document.getElementById('thisqty').value);
c = a*b;
alert(c);
}
</script>

Yes, Use the parseFloat and
Replace the following code

document.getElementById("thisamt").onblur = c;

with

document.getElementById("thisamt").value= c;

If you have more than one textbox with same id that is qty in then that may create problem

Replace this code to sove the same id problem

<td align="center" ><input name="thisqty" type="text" class="thisqty" id="thisqty" value="<?php echo $bdatam["thisqty"];?>" size="12" /></td>
<td align="right"><input name="thisamt" type="text" class="thisamt" id="thisamt" value="<?php echo $thisamt; ?>" readonly="readonly";/></td>

with

<td align="center" ><input name="thisqty" type="text" class="thisqty" id="thisqty<?php echo $i;?>" value="<?php echo $bdatam["thisqty"];?>" size="12" onBlur="line(this.id,'<?php echo $bdatam["sum(curr_amount)"];?>','<?php echo "thisamt".$i;?>')" /></td>
<td align="right"><input name="thisamt" type="text" class="thisamt" id="thisamt<?php echo $i;?>" value="<?php echo $thisamt; ?>" readonly="readonly";/></td>

And the Javascript is

<script type="text/javascript">
function line(elem,amt,res_elem) 
{
	var qty=document.getElementById(elem).value;
	var tot_amt=qty*amt;
	document.getElementById(res_elem).value = tot_amt;
}

</script>

Hi Karthik

Thanks for your post, now its working fine, but we required 2 decimal values.

can you pls help me

For two decimal value replace the javascript with

<script type="text/javascript">
function line(elem,amt,res_elem) 
{
	var qty=document.getElementById(elem).value;
	var tot_amt=qty*amt;
	document.getElementById(res_elem).value = Math.round(tot_amt*100)/100;
}

</script>

Hi Karthik

Thanks for your support to solve the issue.

Thanks my friend

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.