PDA

View Full Version : multiply the cell 1 and cell2 values & show the answer in cell3 textbox when onkeypress event occurs


swetha123
04-27-2009, 05:33 AM
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).innerHTM L);
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

davidj
04-27-2009, 07:00 AM
i need to test this

i will look tonight (GMT) if no one helps

swetha123
04-27-2009, 07:14 AM
i need to test this

i will look tonight (GMT) if no one helps



thanks for the reply davidj
waiting for the reply

davidj
04-27-2009, 07:31 AM
post back if you find a solution before hand

save me the effort