...

View Full Version : Problem in Subtraction



newphpcoder
12-09-2010, 02:19 AM
Good day!

I need to automatically subtract the input qty and output qty and the result should be appear in the text area of qty.

the input qty and output qty depend on the operation name.

i try this code:



<?php
include("config.php");

$query = "SELECT operation_name FROM clt_traceability WHERE operation_name = '01. Spreading'";

$inqty = $_POST['input_qty'];
$outqty = $_POST['output_qty'];
$qty = $_POST['variance_qty'];

$qty = $inqty - $outqty;


?>
<html>
<body>
Input<input type = 'text' name='inqty' id='inqty' />
Output<input type = 'text' name='outqty' id='outqty' />
Qty<input type = 'text' name='qty' id='qty' />
</body>
</hmtl>


in this code when i enter input = 100 output= 50 and when I enter or I used tab no output in qty.

Thank you..

seco
12-09-2010, 02:34 AM
your posts are wrong and you need an echo

newphpcoder
12-09-2010, 02:50 AM
your posts are wrong and you need an echo

i revised my code:



<?php
include("config.php");

$query = "SELECT operation_name FROM clt_traceability WHERE operation_name = '01. Spreading'";
$result = mysql_query($query);

if (mysql_fetch_row($result))
{
$inqty = $_POST['input_qty'];
$outqty = $_POST['output_qty'];
$qty = $_POST['variance_qty'];

$qty = $inqty - $outqty;
}

?>
<html>
<head>
<script language="javascript">
function handleEnter(e, nextfield)
{
var characterCode = (e && e.which)? e.which: e.keyCode;
if(characterCode == 13)
{
document.getElementById(nextfield).focus();
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form action="qty.php" method="post" name="qty">
<?php
echo "Input:<input type='text' name='inqty' id='inqty'onkeypress='return handleEnter(event,\"outqty\");' /><br />";
echo "Output:<input type='text' name='inqty' id='outqty'onkeypress='return handleEnter(event,\"qty\");' /><br />";
echo "Qty:<input type='text' name='inqty' id='qty'onkeypress='return handleEnter(event,\"inqty\");' /><br />";
?>
</form>
</body>
</hmtl>


When i run my test webpage I input 100 in input and 50 in output qty using enter key after i input 100 in input text field the cursor was go to the output text field and when i press the enter theres no output in qty.

I really want to know is how is possible or the code to for automatically that input and output would subtract and the result is appear in qty text field.

Thank you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum