Forum Moderators: coopster

Message Too Old, No Replies

multiply the cell 1 and cell2 values and need show the answer in the c

         

ravii

4:29 am on Apr 27, 2009 (gmt 0)

10+ Year Member



hI,

I used the buttons to get the answer but now i need to multiply the cell 1 and cell2 values and need show the answer in the cell3 textbox when the onkeypress event occurs

but the thing is, it is showing the answer only in first occured cell3 textbox

I need to show the answer in that particualr ROW textbox

when this event fires it calls a function which is in javascript file

hope u understood my doubt

here is my code

test.php

<html>
<head>
<script src="/sample.js"></script>

<body>
<table id="myTable" border="1">
<?php
for($r=1;$r<=3;$r++)
{
$anscell='ans' . $r;
$txtname='txt' . $r;
$cal='cal' .$r;
echo'<tr>
<td id="'.$anscell.'">10</td>
<td><input type="text" name="'.$txtname.'" id="'.$txtname.'" value="" onkeypress="cell('.$r.')"></td>
<td><input type="text" name="'.$cal.'" id="'.$cal.'" ></td>
</tr>';
}
?>
</table>
</body>
</html>

JS file is this

// JavaScript Document
var xmlHttp
function cell(r)
{
var anscell = 'ans'+r;
var txtfield = 'txt'+r;
var cal='cal'+r;
if (document.getElementById(anscell) && document.getElementById(txtfield))
{
var x = parseInt(document.getElementById(anscell).innerHTML);
var y = parseInt(document.getElementById(txtfield).value);
}

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="cal_total.php"
url=url+"?cqty="+y+"&cprice="+x
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged()
{
var cal='cal'+r;
if (xmlHttp.readyState==4 ¦¦ xmlHttp.readyState=="complete")
{
document.getElementById("cal").innerHTML=xmlHttp.responseText
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

cal_total.php

<html>
<head>
</head>
<body>
<?php
$qty=$_GET['cqty'];
$price=$_GET['cprice'];
$tot=$qty*$price;
echo $tot;
?>

</body>
</html>

thanks
swetha

coopster

5:30 pm on May 9, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You will need to keep relativity amongst the rows so you can determine which button was clicked and which cells to use to do the math and also in which to display the results.