Calculating the total in JavaScript
Posted
by DAFFODIL
on Stack Overflow
See other posts from Stack Overflow
or by DAFFODIL
Published on 2010-05-27T01:24:43Z
Indexed on
2010/05/27
2:11 UTC
Read the original article
Hit count: 361
JavaScript
OP, please replace this text with a detailed description of your problem. Your code is below.
I used document.getElementById
but the math is not working. I need total to be calculated:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<script type = "text/javascript">
function a()
{
var q = document.getElementById('ad').value;
document.getElementById('s').value=q + q;
}
</script>
</head>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("form1", $con);
error_reporting(E_ALL ^ E_NOTICE);
$nam=$_GET['msg'];
$row=mysql_query("select * from inv where Name='$nam'");
while($row1=mysql_fetch_array($row))
{
$Name=$row1['Name'];
$Address =$row1['Address'];
$City=$row1['City'];
$Pincode=$row1['Pincode'];
$No=$row1['No'];
$Date=$row1['Date'];
$DCNo=$row1['DCNo'];
$DcDate=$row1['DcDate'];
$YourOrderNo=$row1['YourOrderNo'];
$OrderDate=$row1['OrderDate'];
$VendorCode=$row1['VendorCode'];
$SNo=$row1['SNo'];
$descofgoods=$row1['descofgoods'];
$Qty=$row1['Qty'];
$Rate=$row1['Rate'];
$Amount=$row1['Amount'];
}
?>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="846" border="0">
<tr>
<td width="411" height="113"> </td>
<td width="412"> </td>
</tr>
</table>
<table width="846" border="0">
<tr>
<td height="38"> </td>
</tr>
</table>
<table width="846" border="0">
<tr>
<td width="390" rowspan="4"> </td>
<td width="92" height="35"> </td>
<td width="136"><?php echo $No;?></td>
<td width="36"> </td>
<td width="170"><?php echo $Date;?></td>
</tr>
<tr>
<td height="37"> </td>
<td><?php echo $DCNo;?></td>
<td> </td>
<td><?php echo $DcDate;?></td>
</tr>
<tr>
<td height="34"> </td>
<td><?php echo $YourOrderNo;?></td>
<td> </td>
<td><?php echo $OrderDate;?></td>
</tr>
<tr>
<td height="29"> </td>
<td><?php echo $VendorCode;?></td>
<td> </td>
<td> </td>
</tr>
</table>
<table width="845" border="0">
<tr>
<td height="38"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="34"> </td>
<td width="457"> </td>
<td width="104"> </td>
<td width="79"> </td>
<td width="149"> </td>
</tr>
<?php $i=1;
$row=mysql_query("select * from inv where Name='$nam'");
while($row1=mysql_fetch_array($row))
{
$descofgoods=$row1['descofgoods'];
$Qty=$row1['Qty'];
$Rate=$row1['Rate'];
$Amount=$row1['Amount'];
?>
<tr>
<td><?php echo $i;?></td>
<td><?php echo $descofgoods;?></td>
<td><?php echo $Qty;?></td>
<td><?php echo $Rate;?></td>
<td><input name="Amount" type = "text" id ="ad" value="<?php echo $Amount;?>" /></td>
</tr>
<?php $i++;} ?>
</table>
<table width="844" border="0">
<tr>
<td width="495" height="1065">
<input type="text" name="textfield2" /> </td>
<td width="191"> </td>
<td width="144"><input type="text" name="tot" id="s" onclick="a()"; /></td>
</tr>
© Stack Overflow or respective owner