hi I am really novice in programming and doing some PHP development to support a personal commitment.
I have written a javascript to do some calculations and return the answer. I want to access this value from my php and print it.
following are the code components.
<?php include 'dbconnection.php'; ?>
<?php
$Kg=0.00;
$Rate=0.00; $MinusBags=0.00; $Amount = 0.00;
$KgIntoRate=0.00;
//$Amount = $KgIntoRate - $MinusBags;
//execute the SQL query and return records
$result = mysql_query("SELECT EmployeeName FROM employees");
$result2 = mysql_query("SELECT SRate FROM scraprates where SYear=YEAR(CURRENT_DATE()) AND SMonth=MONTHNAME(CURRENT_DATE())");
$temp1 = mysql_fetch_array($result2);
$Rate = $temp1['SRate'];
//$Rate=mysql_fetch_array($result2);
//fetch the data from the database
try{
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>".$row{'EmployeeName'}."</td>";
echo "<td><input type='text' name='Kg' id='Kg' onChange='CalcKgIntoRate();'/></td>";
echo "<td>".$Rate."</td>";
// $KgIntoRate = $_GET['php_KgIntoRate'];
//echo "<td>".$_GET['php_KgIntoRate']."</td>";
echo "<td>".$KgIntoRate."</td>";
echo "<td><input type='text' name='MinusBags'/></td>";
echo "<td>".$Amount."</td></tr>";
}
}
catch(Exception $e)
{echo "error".$e;}
?>
<script type="text/javascript">
//$Kg= $('#Kg').val();
function CalcKgIntoRate(){
var Kg=document.getElementById('Kg').value;
var php_rate = "<?php echo $Rate; ?>";
var php_KgIntoRate = "<?php echo $KgIntoRate; ?>";
//document.write(Kg);
php_KgIntoRate=Kg*php_rate;
return php_KgIntoRate;
}
</script>
<?php
//function CalcKgIntoRate(){
//$KgIntoRate = $Kg * $Rate;
//echo "<td>".$KgIntoRate."</td>";
//}
//close the connection
mysql_close($dbhandle);
?>
what i want to do is this. Names and Rate are coming from two database tables. I want to calculate KgIntoRate based on the Kg's entered (on change event of text field) and show the value in the Kg * Rate field.
I read that I need to use Ajax. but don't know how to do it. Appreciate some help with the code.