Quote:
Originally Posted by shabbir
You are trying to subtract two numbers in PHP but this can simply be done in plain and simple HTML
See
Code:
<INPUT TYPE="text" NAME="qty1" Value="">
<INPUT TYPE="text" NAME="qty2" value="">
<INPUT TYPE="text" NAME="res" value="">
<INPUT TYPE="submit" onClick="res.value=qty1.value-qty2.value">
Now I understand that you have some added things to be done in PHP and for that you have to use the POST to get the value, do the calc and then show again.
this is the new test code:
PHP Code:
PHP Code:
<?php
include("config.php");
$qty = 0;
if($_POST['submit']){
$inqty = $_POST['inqty'];
$outqty = $_POST['outqty'];
}
$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="testqty">
Input:<input type='text' name='inqty' id='inqty' />
Output:<input type='text' name='outqty' id='outqty'/> <br>
Qty:<input type='text' name='qty' id='qty' value = '<?php echo $qty; ?>' /><br>
<input type='submit' value='save' name='submit' id='submit'>
</form>
</body>
</hmtl>
In this code the qty was appear after I click the save button.
I want to happen is After I input numbers in input qty I press the enter key then the cursor will be in the output qty then after i input numbers in output text filed and I press the enter key the result should be appear automatically without pressing the button.
I try this code:
PHP Code:
PHP Code:
<?php
include("config.php");
$qty = 0;
if($_POST['qty']){
$inqty = $_POST['inqty'];
$outqty = $_POST['outqty'];
}
$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="testqty">
<?php
echo"Input:<input type='text' name='inqty' id='inqty' onkeypress='return handleEnter(event,\"outqty\");' />";
echo"Output:<input type='text' name='outqty' id='outqty' onkeypress='return handleEnter(event,\"qty\");' /> <br>";
echo "Qty:<input type='text' name='qty' id='qty' value = '<?php echo $qty; ?>' onkeypress='return handleEnter(event,\"inqty\");' />";
?>
</form>
</body>
</hmtl>
The output of this code is the value of the text field of qty was the <?php echo $qty; ?>
Thank you