aki2all 0 Newbie Poster
<?php
 include 'functions.php';
if(!loggedin())
{
 header("Location: index.html");
 exit();
}

    $session = $_SESSION['empno'];

    $dbName = mysql_query("SELECT ename FROM employee
                        WHERE empno = '$session'") or die(mysql_error());
    $nameResult = mysql_fetch_array($dbName);
    $name = $nameResult['ename'];

    $reqno = $_GET['id']; //echo $reqno; exit;
    $amtApproved = $_GET['amtApproved'];    
    $query = mysql_query("SELECT * FROM requisition
                        WHERE reqno = '$reqno'") or die(mysql_error());
        $result = mysql_fetch_assoc($query);
        $online1 = $result['online']; //echo $purpose; //exit;
        $cash1 = $result['cash']; //echo $amount; exit;
    //$id = $reqno;

    if (isset($_POST['submit'])){
        //echo $id; exit;
        //echo $reqno; exit;//= $_GET['id'];
        $online = mysql_real_escape_string($_POST['online']); //echo $purpose1;
        $cash = mysql_real_escape_string($_POST['cash']); //echo $amount1; exit;
        $sum = $online+$cash;
        if($sum==$amtApproved && $online1!=NULL && $cash1!=NULL){
            $update = mysql_query("UPDATE requisition
                                SET online = '".$online."', cash = '".$cash."'
                                WHERE reqno = '$reqno'") or die(mysql_error());
            header ("Location: main.php");
        }
        echo "Wrong entry!!";
    }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<title>Main</title>


<style type="text/css">
<!--
body {
    background-image: url(images/iicb-06.jpg);
}
.style3 {font-size: 24px}
-->
</style></head>

<body>


<div align="center">
  <style type="text/css">
<!--

  </style>
  <body bgcolor = "#d3dfca">
  <style type="text/css">
<!--
.style3 {
    font-weight: bold;
    color: #fdfdsd;
    font-size: large;
}
-->
    </style>

  <img src="images/iicb.png">
</div>
<h1 align="center">Split Your Approved Amount</h1>
<div align="center">
<?php 

?> </div>
<form action="<? $_SERVER['PHP_SELF']?>" method="post"><table align="center" cellpadding="5" cellspacing="5">
<tr><th><span class="style3">Requisition Number</span></th>
<td><span class="style3"></span><?php echo $reqno?></td>
</tr>
<tr><th><span class="style3">Your Approved Amount</span></th>
<td><?php  echo $amtApproved ?></td></tr>
<tr><th>Online</th><td><input type="text" name="online" /></td></tr>
<tr><th>Cash</th><td><input type="text" name="cash" /></td></tr>
</table>
<div align="center"><input type="submit" name="submit" id="submit" value="Submit" /></div>
</form>



</body>
</html>

I want to have a javascript that automatically calculates the difference of the filled-in amount and the total amount.
Please Help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.