Log in

View Full Version : Problem in Subtraction



rhodarose
12-09-2010, 02:15 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..

Nile
12-09-2010, 03:37 AM
You need to set one of the values of the text box, but make sure you use isset() before you do that so you know if the user even submitted something or not.

rhodarose
12-09-2010, 05:18 AM
As I've on my first thread, that code is for testing purposes only. Now I will post the real code of my webpage which I need to add code for subtracting input qty and output qty and the result is automatically display in qty text field.



<?php
include("config.php");
$rexist = 0;
if($_POST["no"])
{
$clt_date = $_POST["date"];
$query = "INSERT INTO clt (no, ac2l, b3, type, roll, t_date, date) VALUES ('" . $_POST["no"] . "', '" . $_POST["ac2l"] . "', '" . $_POST["b3"] . "', '" . $_POST["type"] . "', '" . $_POST["roll"] . "', now(), '" . $date . "')";
$result = mysql_query($query);
$transact_id = mysql_insert_id();

$opname = $_POST["opname"];
$timein = $_POST["timein"];
$timeout = $_POST["timeout"];
$inqty = $_POST["inqty"];
$iun = $_POST["iun"];
$outqty = $_POST["outqty"];
$oun = $_POST["oun"];
$idno = $_POST["idno"];
$mcno = $_POST["mcno"];
$varqty = $_POST["varqty"];
$varsublot = $_POST["varsublot"];
$dateshift = $_POST["dateshift"];
$shift = $_POST["shift"];

$totalarr = count($opname) - 1;
for($ctr=0; $ctr < $totalarr; $ctr++)
{
$inqty[$ctr] = (float) $inqty[$ctr];
$varqty[$ctr] = (float) $varqty[$ctr];
$outqty[$ctr] = (float) $outqty[$ctr];
$query = "INSERT INTO traceability (operation_name, time_in, time_out, input_qty, input_unit, output_qty, output_unit, id_no, mc_no, variance_qty, variance_sublot, date, shift, transact_id) VALUES ('" . $opname[$ctr] . "', '" . $timein[$ctr] . "', '" . $timeout[$ctr] . "', '" . $inqty[$ctr] . "' , '" . $iun[$ctr] . "' ,'" . $outqty[$ctr] . "', '" . $oun[$ctr] . "' , '" . $idno[$ctr] . "', '" . $mcno[$ctr] . "', '" . $varqty[$ctr] . "', '" . $varsublot[$ctr] . "', '" . $dateshift[$ctr] . "', '" . $shift[$ctr] . "', '" . $transact_id . "')";
$result = mysql_query($query);

}
}
$rexist = 0;
?>
<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 onLoad="document.type.no.focus();">
<!--<p><a href="definition.php">Types</a><a href="query.php">Query</a></p>-->
<?php
include("menu.php");
?>
<form action="main.php" method="post" name="type">
<?php
$rexist = 1;
echo "<p>No:<input type='text' name='_no' onkeypress='return handleEnter(event,\"date\");' /><br />";
echo "Date:;<input type='text' name='date' onkeypress='return handleEnter(event,\"ac2l\");' /></p>";

echo "<table>";
echo "<tr><th class='myclass'>TRACEABILITY</th><th class='myclass'>LOT #</th></tr>";
echo "<tr><td>AC2L</td><td><input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,\"b3\");' /></td></tr>";
echo "<tr><td>B3</td><td><input type='text' name='b3' id='b3' onkeypress='return handleEnter(event,\"type\");' /></td></tr>";
echo "<tr><td>Type</td><td><input type='text' name='type' id='type' onkeypress='return handleEnter(event,\"roll\");' /></td></tr>";
echo "<tr><td>Roll</td><td><input type='text' name='roll' id='roll' onkeypress='return handleEnter(event,\"timein0\");' /></td></tr>";
echo "</table>";
echo "<p>&nbsp;</p>";

$query = "SELECT * FROM trace_operations ORDER BY operation_name";
$last_operation_name = "";
$result = mysql_query($query);
if($result)
{
$rexist = 1;
echo "<p><center><b>TRACEABILITY</center></b></p>";
echo "<table>";
echo "<tr><th class='myclass'>OPERATIONS</th><th class='myclass'>Time IN</th><th class='myclass'>Time OUT</th><th class='myclass'>INPUT <br/> QTY</th><th class='myclass'>UNIT</th><th class='myclass'>OUTPUT QTY</th><th class='myclass'>UNIT</th><th class='myclass'>NAME & ID #</th><th class='myclass'>MC #</th><th class='myclass'>VARIANCE Qty</th><th class='myclass'>VARIANCE Sub Lot</th><th class='myclass'>DATE</th><th class='myclass'>SHIFT</th></tr>";
$totalrows = mysql_num_rows($result);
$trows = $totalrows - 1;
for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;
echo "\n\t<tr>";
echo "\n\t\t<td>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t\t<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t\t<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t\t<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='varsublot[]' id='varsublot" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"timein" . $tctr . "\");' /></td>";
echo "\n\t</tr>";
}
if($totalrows > 1);
{
$row = mysql_fetch_array($result);
echo "\n\t<tr>";
echo "\n\t\t<td>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t\t<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t\t<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t\t<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='varsublot[]' id='varsublot" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"saveform\");' /></td>";
echo "\n\t</tr>";
}
echo "</table>";
}
echo "<p><input type='submit' value=' Save ' id='saveform' /></p>";
echo "<input type='hidden' name='typeno' value='" . $_POST["typeno"] . "' />";
?>
</form>
</body>
</html>


I need to subtract input qty to output qty then the result is automatically display in qty text field, I want it to happen in the operation is 01. Spread and 03. Pack

Nile
12-09-2010, 12:51 PM
Hmm, you want the user to see 10 in the qty input exactly when the person types 15 and 5 without pressing the submit button?

rhodarose
12-10-2010, 12:02 AM
Hmm, you want the user to see 10 in the qty input exactly when the person types 15 and 5 without pressing the submit button?

Yes...thats i want to happen

rhodarose
12-10-2010, 12:04 AM
Now I will post the real code of my webpage which I need to add code for subtracting input qty and output qty and the result is automatically display in qty text field.




<?php

include("config.php");

$rexist = 0;

if($_POST["no"])

{

$clt_date = $_POST["date"];

$query = "INSERT INTO clt (no, ac2l, b3, type, roll, t_date, date) VALUES ('" . $_POST["no"] . "', '" . $_POST["ac2l"] . "', '" . $_POST["b3"] . "', '" . $_POST["type"] . "', '" . $_POST["roll"] . "', now(), '" . $date . "')";

$result = mysql_query($query);

$transact_id = mysql_insert_id();



$opname = $_POST["opname"];

$timein = $_POST["timein"];

$timeout = $_POST["timeout"];

$inqty = $_POST["inqty"];

$iun = $_POST["iun"];

$outqty = $_POST["outqty"];

$oun = $_POST["oun"];

$idno = $_POST["idno"];

$mcno = $_POST["mcno"];

$varqty = $_POST["varqty"];

$varsublot = $_POST["varsublot"];

$dateshift = $_POST["dateshift"];

$shift = $_POST["shift"];



$totalarr = count($opname) - 1;

for($ctr=0; $ctr < $totalarr; $ctr++)

{

$inqty[$ctr] = (float) $inqty[$ctr];

$varqty[$ctr] = (float) $varqty[$ctr];

$outqty[$ctr] = (float) $outqty[$ctr];

$query = "INSERT INTO traceability (operation_name, time_in, time_out, input_qty, input_unit, output_qty, output_unit, id_no, mc_no, variance_qty, variance_sublot, date, shift, transact_id) VALUES ('" . $opname[$ctr] . "', '" . $timein[$ctr] . "', '" . $timeout[$ctr] . "', '" . $inqty[$ctr] . "' , '" . $iun[$ctr] . "' ,'" . $outqty[$ctr] . "', '" . $oun[$ctr] . "' , '" . $idno[$ctr] . "', '" . $mcno[$ctr] . "', '" . $varqty[$ctr] . "', '" . $varsublot[$ctr] . "', '" . $dateshift[$ctr] . "', '" . $shift[$ctr] . "', '" . $transact_id . "')";

$result = mysql_query($query);



}

}

$rexist = 0;

?>

<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 onLoad="document.type.no.focus();">

<!--<p><a href="definition.php">Types</a><a href="query.php">Query</a></p>-->

<?php

include("menu.php");

?>

<form action="main.php" method="post" name="type">

<?php

$rexist = 1;

echo "<p>No:<input type='text' name='_no' onkeypress='return handleEnter(event,\"date\");' /><br />";

echo "Date:;<input type='text' name='date' onkeypress='return handleEnter(event,\"ac2l\");' /></p>";



echo "<table>";

echo "<tr><th class='myclass'>TRACEABILITY</th><th class='myclass'>LOT #</th></tr>";

echo "<tr><td>AC2L</td><td><input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,\"b3\");' /></td></tr>";

echo "<tr><td>B3</td><td><input type='text' name='b3' id='b3' onkeypress='return handleEnter(event,\"type\");' /></td></tr>";

echo "<tr><td>Type</td><td><input type='text' name='type' id='type' onkeypress='return handleEnter(event,\"roll\");' /></td></tr>";

echo "<tr><td>Roll</td><td><input type='text' name='roll' id='roll' onkeypress='return handleEnter(event,\"timein0\");' /></td></tr>";

echo "</table>";

echo "<p>&nbsp;</p>";



$query = "SELECT * FROM trace_operations ORDER BY operation_name";

$last_operation_name = "";

$result = mysql_query($query);

if($result)

{

$rexist = 1;

echo "<p><center><b>TRACEABILITY</center></b></p>";

echo "<table>";

echo "<tr><th class='myclass'>OPERATIONS</th><th class='myclass'>Time IN</th><th class='myclass'>Time OUT</th><th class='myclass'>INPUT <br/> QTY</th><th class='myclass'>UNIT</th><th class='myclass'>OUTPUT QTY</th><th class='myclass'>UNIT</th><th class='myclass'>NAME & ID #</th><th class='myclass'>MC #</th><th class='myclass'>VARIANCE Qty</th><th class='myclass'>VARIANCE Sub Lot</th><th class='myclass'>DATE</th><th class='myclass'>SHIFT</th></tr>";

$totalrows = mysql_num_rows($result);

$trows = $totalrows - 1;

for($ctr = 0; $ctr < $trows; $ctr++)

{

$row = mysql_fetch_array($result);

$tctr = $ctr + 1;

echo "\n\t<tr>";

echo "\n\t\t<td>";

if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];

$last_operation_name = $row["operation_name"];

echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";

echo "\n\t\t<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";

echo "\n\t\t<td>" . $row["input_unit"];

echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";

echo "\n\t\t<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";

echo "\n\t\t<td>" . $row["output_unit"];

echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";

echo "\n\t\t<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='varsublot[]' id='varsublot" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"timein" . $tctr . "\");' /></td>";

echo "\n\t</tr>";

}

if($totalrows > 1);

{

$row = mysql_fetch_array($result);

echo "\n\t<tr>";

echo "\n\t\t<td>";

if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];

$last_operation_name = $row["operation_name"];

echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";

echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";

echo "\n\t\t<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";

echo "\n\t\t<td>" . $row["input_unit"];

echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";

echo "\n\t\t<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";

echo "\n\t\t<td>" . $row["output_unit"];

echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";

echo "\n\t\t<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='varsublot[]' id='varsublot" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>";

echo "\n\t\t<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"saveform\");' /></td>";

echo "\n\t</tr>";

}

echo "</table>";

}

echo "<p><input type='submit' value=' Save ' id='saveform' /></p>";

echo "<input type='hidden' name='typeno' value='" . $_POST["typeno"] . "' />";

?>

</form>

</body>

</html>



I need to subtract input qty to output qty then the result is automatically display in qty text field, I want it to happen in the operation is 01. Spread and 03. Pack

rhodarose
12-10-2010, 12:05 AM
i want to happen is after I enter numbers in input and output and I press enter the result would be show in qty eventhough the next to output is id#

rhodarose
12-10-2010, 12:06 AM
this is the new test 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

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

rhodarose
12-10-2010, 12:39 AM
I revised my code:



PHP Code:
include("config.php");

?>

<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>
-->

<script language="javascript" >
var inqty = document.getElementById('inqty')
var outqty = document.getElementById('outqty')

myqty = inqty - outqty
document.form-name.myqty.value = myqty

</script>
</head>
<body>
<form action="qty.php" method="post" name="form-name">

Input:<input type='text' name='inqty' id='inqty' />
Output:<input type='text' name='outqty' id='outqty'/> <br>
Qty:<input type='text' name='myqty' id='myqty' /><br>
</form>
</body>
</html>


And it did not work

Nile
12-10-2010, 12:51 AM
Please dont double post.


<script type="text/javascript">
var subtract = function(c, b, output){
output.value = c.value-b.value;
}
</script>
<input type="text" id="c" value="0"/>-<input type="text" id="b" value="0"/>=<input type="text" id="a" value="0"/>
<script type="text/javascript">
document.getElementById('c').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'));
}
document.getElementById('b').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'));
}
</script>

rhodarose
12-10-2010, 01:01 AM
Please dont double post.


<script type="text/javascript">
var subtract = function(c, b, output){
output.value = c.value-b.value;
}
</script>
<input type="text" id="c" value="0"/>-<input type="text" id="b" value="0"/>=<input type="text" id="a" value="0"/>
<script type="text/javascript">
document.getElementById('c').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'));
}
document.getElementById('b').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'));
}
</script>

I have code for press enter key like this:



<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>


In my real webpage the following textfield is input qty, output qty, id#, mc# ,and qty. It is possible that after I input number in output qty automatic the result will be appear in qty?

Thank you..I'm sorry if i accidentall double post my thread.

Nile
12-10-2010, 01:12 AM
I dont understand? Just play around with my code..

rhodarose
12-10-2010, 01:13 AM
What is the condition for only the operation name oper 1,oper 3, and oper 4 would only subtract the input and output?

Thank you..

I will try to add the code that you given in my webpage code.


Thank you so much

rhodarose
12-10-2010, 01:14 AM
I dont understand? Just play around with my code..

Did you see my previous posted code which is the real code of my webpage?In that code I want to add the code for subtraction.

Nile
12-10-2010, 01:15 AM
Copy and paste my code where you want it and use it accordingly

rhodarose
12-10-2010, 01:29 AM
I dont understand? Just play around with my code..

Did you see my previous post, my webpage code?

Nile
12-10-2010, 01:33 AM
Yes, I did. If my code above was not what you wanted could you explain it in different words?

rhodarose
12-10-2010, 01:36 AM
Copy and paste my code where you want it and use it accordingly



<?php
include("config.php");
$rexist = 0;
if($_POST["no"])
{
$clt_date = $_POST["date"];
$query = "INSERT INTO clt (no, ac2l, b3, type, roll, t_date, date) VALUES ('" . $_POST["no"] . "', '" . $_POST["ac2l"] . "', '" . $_POST["b3"] . "', '" . $_POST["type"] . "', '" . $_POST["roll"] . "', now(), '" . $date . "')";
$result = mysql_query($query);
$transact_id = mysql_insert_id();

$opname = $_POST["opname"];
$timein = $_POST["timein"];
$timeout = $_POST["timeout"];
$inqty = $_POST["inqty"];
$iun = $_POST["iun"];
$outqty = $_POST["outqty"];
$oun = $_POST["oun"];
$idno = $_POST["idno"];
$mcno = $_POST["mcno"];
$varqty = $_POST["varqty"];
$varsublot = $_POST["varsublot"];
$dateshift = $_POST["dateshift"];
$shift = $_POST["shift"];

$totalarr = count($opname) - 1;
for($ctr=0; $ctr < $totalarr; $ctr++)
{
$inqty[$ctr] = (float) $inqty[$ctr];
$varqty[$ctr] = (float) $varqty[$ctr];
$outqty[$ctr] = (float) $outqty[$ctr];
$query = "INSERT INTO traceability (operation_name, time_in, time_out, input_qty, input_unit, output_qty, output_unit, id_no, mc_no, variance_qty, variance_sublot, date, shift, transact_id) VALUES ('" . $opname[$ctr] . "', '" . $timein[$ctr] . "', '" . $timeout[$ctr] . "', '" . $inqty[$ctr] . "' , '" . $iun[$ctr] . "' ,'" . $outqty[$ctr] . "', '" . $oun[$ctr] . "' , '" . $idno[$ctr] . "', '" . $mcno[$ctr] . "', '" . $varqty[$ctr] . "', '" . $varsublot[$ctr] . "', '" . $dateshift[$ctr] . "', '" . $shift[$ctr] . "', '" . $transact_id . "')";
$result = mysql_query($query);

}
}
$rexist = 0;
?>
<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>
<script type="text/javascript">
var subtract = function(inqty, outqty, result){
result.value = inqty.value-outqty.value;
}
</script>
<script type="text/javascript">
document.getElementById('inqty').onmousedown = function(){
subtract(document.getElementById('inqty'), document.getElementById('outqty'), document.getElementById('varqty'));
}
document.getElementById('outqty').onmousedown = function(){
subtract(document.getElementById('inqty'), document.getElementById('outqty'), document.getElementById('varqty'));
}
</script>
</head>
<body onLoad="document.type.no.focus();">
<!--<p><a href="definition.php">Types</a><a href="query.php">Query</a></p>-->
<?php
include("menu.php");
?>
<form action="main.php" method="post" name="type">
<?php
$rexist = 1;
echo "<p>No:<input type='text' name='_no' onkeypress='return handleEnter(event,\"date\");' /><br />";
echo "Date:;<input type='text' name='date' onkeypress='return handleEnter(event,\"ac2l\");' /></p>";

echo "<table>";
echo "<tr><th class='myclass'>TRACEABILITY</th><th class='myclass'>LOT #</th></tr>";
echo "<tr><td>AC2L</td><td><input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,\"b3\");' /></td></tr>";
echo "<tr><td>B3</td><td><input type='text' name='b3' id='b3' onkeypress='return handleEnter(event,\"type\");' /></td></tr>";
echo "<tr><td>Type</td><td><input type='text' name='type' id='type' onkeypress='return handleEnter(event,\"roll\");' /></td></tr>";
echo "<tr><td>Roll</td><td><input type='text' name='roll' id='roll' onkeypress='return handleEnter(event,\"timein0\");' /></td></tr>";
echo "</table>";
echo "<p>&nbsp;</p>";

$query = "SELECT * FROM trace_operations ORDER BY operation_name";
$last_operation_name = "";
$result = mysql_query($query);
if($result)
{
$rexist = 1;
echo "<p><center><b>TRACEABILITY</center></b></p>";
echo "<table>";
echo "<tr><th class='myclass'>OPERATIONS</th><th class='myclass'>Time IN</th><th class='myclass'>Time OUT</th><th class='myclass'>INPUT <br/> QTY</th><th class='myclass'>UNIT</th><th class='myclass'>OUTPUT QTY</th><th class='myclass'>UNIT</th><th class='myclass'>NAME & ID #</th><th class='myclass'>MC #</th><th class='myclass'>VARIANCE Qty</th><th class='myclass'>VARIANCE Sub Lot</th><th class='myclass'>DATE</th><th class='myclass'>SHIFT</th></tr>";
$totalrows = mysql_num_rows($result);
$trows = $totalrows - 1;
for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;
echo "\n\t<tr>";
echo "\n\t\t<td>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t\t<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t\t<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t\t<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='varsublot[]' id='varsublot" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"timein" . $tctr . "\");' /></td>";
echo "\n\t</tr>";
}
if($totalrows > 1);
{
$row = mysql_fetch_array($result);
echo "\n\t<tr>";
echo "\n\t\t<td>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t\t<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t\t<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t\t<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='varsublot[]' id='varsublot" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"saveform\");' /></td>";
echo "\n\t</tr>";
}
echo "</table>";
}
echo "<p><input type='submit' value=' Save ' id='saveform' /></p>";
echo "<input type='hidden' name='typeno' value='" . $_POST["typeno"] . "' />";
?>
</form>
</body>
</html>



I got an error in line 30

Nile
12-10-2010, 01:38 AM
What was the error displayed?

rhodarose
12-10-2010, 02:08 AM
What was the error displayed?

here is the error
Line: 31
Error: 'document.getElementById(...)' is null or not an object

Nile
12-10-2010, 02:25 AM
Please post a link to the page on your site that contains the problematic script so we can check it out.
I'm sorry, I was confused. I thought this was a PHP error - can you paste line 31 here and provide a link to your page?

rhodarose
12-10-2010, 02:48 AM
Please post a link to the page on your site that contains the problematic script so we can check it out.
I'm sorry, I was confused. I thought this was a PHP error - can you paste line 31 here and provide a link to your page?

In the code:



<html>
<head>
<script type="text/javascript">
var subtract = function(c, b, output){
output.value = c.value-b.value;


}
</script>
<input type="text" id="c" value="0"/>-<input type="text" id="b" value="0"/>=<input type="text" id="a" value="0"/><br/>
<input type="text" id="d" value="0" />
<script type="text/javascript">
document.getElementById('c').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d'));
}
document.getElementById('b').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d'));
}
</script>
</head>
</html>


how can i used it in php and also the onkeyenter because in my real webpage my code for input type is like this:



echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";

and i have this code:
</style>
<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>

rhodarose
12-10-2010, 02:49 AM
my webpage was on localhost

rhodarose
12-10-2010, 02:53 AM
I'm sorry, because I'm not good in codeing and analyzing..I really need to fix this problem..

Thank you

Nile
12-10-2010, 03:18 AM
Give the ids of c, b, and a to the right ones (c = first number, b = second, a = result, because c-b=a, and a+b=c)

rhodarose
12-10-2010, 03:29 AM
Give the ids of c, b, and a to the right ones (c = first number, b = second, a = result, because c-b=a, and a+b=c)

You mean it should be like this


echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='a" . $ctr . "' onkeypress='return handleEnter(event,\"b" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='b" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='c" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";

how about this code:
<script type="text/javascript">
document.getElementById('c').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d'));
}
document.getElementById('b').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d'));
}
</script>


It is onmousedown , I want it press enter.

rhodarose
12-10-2010, 03:35 AM
Honestly, I don't know where i can put the code you suggeted. I really need to fix this problem, i don't know why, I'm sorry I'm not good in coding and analyzing.



I only want is the input and output should be subtract and the result would appear in varqty text field. when they press enter key.

Thank you

Nile
12-10-2010, 03:38 AM
It should be like this:


echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='c" . $ctr . "' onkeypress='return handleEnter(event,\"b" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='b" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='a" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";

how about this code:
<script type="text/javascript">
document.getElementById('c').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d'));
}
document.getElementById('b').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d'));
}
</script>

Tell me if that works, then I'll do the enter.

rhodarose
12-10-2010, 03:47 AM
It should be like this:


echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='c" . $ctr . "' onkeypress='return handleEnter(event,\"b" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='b" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='a" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";

how about this code:
<script type="text/javascript">
document.getElementById('c').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d'));
}
document.getElementById('b').onmousedown = function(){
subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d'));
}
</script>

Tell me if that works, then I'll do the enter.

I tried it and I got this error:

Line: 30
Error: 'document.getElementById(...)' is null or not an object

Nile
12-10-2010, 09:23 PM
This should do it:


<input type="text" id="c" value="0"/>-<input type="text" id="b" value="5"/>=<input disabled type="text" id="a" value="0" style="color:#000" />
<script type="text/javascript">
var c = document.getElementById('c');
var b = document.getElementById('b');
var a = document.getElementById('a');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>

rhodarose
12-10-2010, 11:49 PM
This should do it:


<input type="text" id="c" value="0"/>-<input type="text" id="b" value="5"/>=<input disabled type="text" id="a" value="0" style="color:#000" />
<script type="text/javascript">
var c = document.getElementById('c');
var b = document.getElementById('b');
var a = document.getElementById('a');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>


I got this error:

Line: 17
Error: 'c' is null or not an object

rhodarose
12-11-2010, 01:13 AM
this code is for subtraction of input and output using javascript


<html>
<head>
<script type= "text/javascript">
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
var qty = new Array(2);
qty[0] = parseFloat(document.myform.inqty.value);
qty[1] = parseFloat(document.myform.outqty.value);

myqtyval = qty[0]-qty[1];
document.myform.myqty.value = myqtyval;
}

function stopCalc(){
clearInterval(interval);
}
</script>
</head>
<body>
<form name='myform' action='test.php' method='post'>
Input<input type='text' name='inqty' onFocus='startCalc();' onBlur='stopCalc();' />
Output<input type='text' name='outqty' onFocus='startCalc();' onBlur='stopCalc();' /><br/>
myqty<input type='text' name='myqty' value='' />
<input type='submit' name='submit' value='save' />


</form>
</body>
</html>

rhodarose
12-11-2010, 01:14 AM
My problem is how can I insert this code in my real codes where i need to have to subtract automatic the input and output of operation name 01 Spreading and 03 Setting. I'm sorry because I'm not good in mixing codes.


<?php
include("config.php");
$rexist = 0;
if($_POST["clt_no"])
{
$clt_date = $_POST["clt_date"];
$query = "INSERT INTO clt_transact (clt_no, ac2l, b3, cloth_type, roll_no, transact_date, clt_date, pack_setting) VALUES ('" . $_POST["clt_no"] . "', '" . $_POST["ac2l"] . "', '" . $_POST["b3"] . "', '" . $_POST["cloth_type"] . "', '" . $_POST["roll_no"] . "', now(), '" . $clt_date . "', '" . $_POST["pack"] . "')";
$result = mysql_query($query);
$clt_transact_id = mysql_insert_id();

$opname = $_POST["opname"];
$timein = $_POST["timein"];
$timeout = $_POST["timeout"];
$inqty = $_POST["inqty"];
$iun = $_POST["iun"];
$outqty = $_POST["outqty"];
$oun = $_POST["oun"];
$idno = $_POST["idno"];
$mcno = $_POST["mcno"];
$varqty = $_POST["varqty"];
$varsublot = $_POST["varsublot"];
$dateshift = $_POST["dateshift"];
$shift = $_POST["shift"];

$totalarr = count($opname) - 1;
for($ctr=0; $ctr < $totalarr; $ctr++)
{
$inqty[$ctr] = (float) $inqty[$ctr];
$varqty[$ctr] = (float) $varqty[$ctr];
$outqty[$ctr] = (float) $outqty[$ctr];
$query = "INSERT INTO clt_traceability (operation_name, time_in, time_out, input_qty, input_unit, output_qty, output_unit, id_no, mc_no, variance_qty, variance_sublot, date, shift, clt_transact_id) VALUES ('" . $opname[$ctr] . "', '" . $timein[$ctr] . "', '" . $timeout[$ctr] . "', '" . $inqty[$ctr] . "' , '" . $iun[$ctr] . "' ,'" . $outqty[$ctr] . "', '" . $oun[$ctr] . "' , '" . $idno[$ctr] . "', '" . $mcno[$ctr] . "', '" . $varqty[$ctr] . "', '" . $varsublot[$ctr] . "', '" . $dateshift[$ctr] . "', '" . $shift[$ctr] . "', '" . $clt_transact_id . "')";
$result = mysql_query($query);

}
}
$rexist = 0;
?>
<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 onLoad="document.clttype.clt_no.focus();">
<!--<p><a href="clt_definition.php">Clt Types</a>&nbsp;&nbsp;&nbsp;<a href="clt_query.php">Query</a></p>-->
<?php
include("menu.php");
?>
<form action="clt_main.php" method="post" name="clttype">
<?php
$rexist = 1;

echo "Clt No:<input type='text' name='clt_no' onkeypress='return handleEnter(event,\"clt_date\");' />";
echo "<input type='radio' name='pack' id='mother' value='Mother Lot' /> Mother Lot<br />";
echo "CLT Date:<input type='text' name='clt_date' onkeypress='return handleEnter(event,\"ac2l\");' />";
echo "<input type='radio' name='pack' id='child' value='Child Lot' /> Child Lot";

echo "<table>";
echo "<tr><th class='myclass'>PARTS</th><th class='myclass'>LOT/BATCH #</th></tr>";
echo "<tr><td>AC2L</td><td><input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,\"b3\");' /></td></tr>";
echo "<tr><td>B3</td><td><input type='text' name='b3' id='b3' onkeypress='return handleEnter(event,\"cloth_type\");' /></td></tr>";
echo "<tr><td>Cloth Type</td><td><input type='text' name='cloth_type' id='cloth_type' onkeypress='return handleEnter(event,\"roll_no\");' /></td></tr>";
echo "<tr><td>Roll No</td><td><input type='text' name='roll_no' id='roll_no' onkeypress='return handleEnter(event,\"timein0\");' /></td></tr>";
echo "</table>";
echo "<p>&nbsp;</p>";

$query = "SELECT * FROM clt_trace_operations ORDER BY operation_name";
$last_operation_name = "";
$result = mysql_query($query);
if($result)
{
$rexist = 1;
echo "<p><center><b>OPERATOR AND MACHINE TRACEABILITY</center></b></p>";
echo "<table>";
echo "<tr><th class='myclass'>OPERATIONS</th><th class='myclass'>Time IN</th><th class='myclass'>Time OUT</th><th class='myclass'>INPUT <br/> QTY</th><th class='myclass'>UNIT</th><th class='myclass'>OUTPUT QTY</th><th class='myclass'>UNIT</th><th class='myclass'>ID #</th><th class='myclass'>MC #</th><th class='myclass'>VARIANCE Qty</th><th class='myclass'>VARIANCE Sub Lot</th><th class='myclass'>DATE</th><th class='myclass'>SHIFT</th></tr>";
$totalrows = mysql_num_rows($result);
$trows = $totalrows - 1;
for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;
echo "\n\t<tr>";
echo "\n\t\t<td>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
echo "\n\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='varsublot[]' id='varsublot" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>";
echo "\n\t<td><input ' type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"timein" . $tctr . "\");' /></td>";
echo "\n\t</tr>";
}
if($totalrows > 1);
{
$row = mysql_fetch_array($result);
echo "\n\t<tr>";
echo "\n\t<td >";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
echo "\n\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t<td><input type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t<td><input type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='varsublot[]' id='varsublot" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>";
echo "\n\t<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"saveform\");' /></td>";
echo "\n\t</tr>";
}
echo "</table>";
}
echo "<p><input type='submit' value=' Save ' id='saveform' /></p>";
echo "<input type='hidden' name='clt_typeno' value='" . $_POST["clt_typeno"] . "' />";
?>
</form>
</body>
</html>

Nile
12-12-2010, 06:15 PM
echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";

and i have this code:
</style>
<script type="text/javascript">
var c = document.getElementById('c');
var b = document.getElementById('b');
var a = document.getElementById('a');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>

rhodarose
12-13-2010, 12:24 AM
echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";

and i have this code:
</style>
<script type="text/javascript">
var c = document.getElementById('c');
var b = document.getElementById('b');
var a = document.getElementById('a');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>


Is it the code I need to used?my problem is my text field was in array ?

Nile
12-13-2010, 12:34 AM
Yes? Use this code..

rhodarose
12-13-2010, 12:55 AM
Yes? Use this code..

Is it I will change the abc into inqty,outqrty,qty?

Nile
12-13-2010, 01:02 AM
If you cant change the IDs to abc, change the code:


var c = document.getElementById('c');
var b = document.getElementById('b');
var a = document.getElementById('a');

And replace the highlighted with your ID

rhodarose
12-13-2010, 01:16 AM
If you cant change the IDs to abc, change the code:


var c = document.getElementById('c');
var b = document.getElementById('b');
var a = document.getElementById('a');

And replace the highlighted with your ID

I used this code:

<script type="text/javascript">
var c = document.getElementById('inqty');
var b = document.getElementById('outqty');
var a = document.getElementById('varqty');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>

Line: 38
Error: 'c' is null or not an object:confused:

Nile
12-13-2010, 01:20 AM
Are you putting this under your input types? What browser?

rhodarose
12-13-2010, 01:32 AM
Are you putting this under your input types? What browser?

I put it on the inside of head after my code in enter key . I used IE 8

Nile
12-13-2010, 01:49 AM
Put it at the bottom of your page before </body>

rhodarose
12-13-2010, 01:57 AM
Put it at the bottom of your page before </body>

i put it after <body>
and still i encountered error.

Nile
12-13-2010, 02:08 AM
It should go right before </body>, not after <body>

rhodarose
12-13-2010, 02:11 AM
It should go right before </body>, not after <body>

Still I got the same error:confused:

Nile
12-13-2010, 02:20 AM
Go to View->Page Source, and copy and paste that.

rhodarose
12-13-2010, 02:57 AM
Go to View->Page Source, and copy and paste that.

What?

Nile
12-13-2010, 03:07 AM
In internet explorer where you are getting this error, go to view->page source, and copy and paste all of that.

rhodarose
12-13-2010, 03:21 AM
In internet explorer where you are getting this error, go to view->page source, and copy and paste all of that.

I'm sorry, I used nusphere to test my codes.

I will attach my whole code

rhodarose
12-13-2010, 03:34 AM
I have the select statement code where only those operation name could subtract the input and output



SELECT t.operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name in ('operation_name1', 'operation_name3', 'operation_name4', 'operation_name5') AND t.clt_transact_id = c.clt_transact_id


my problem is where i can put this code in my php file and how thus the input and output subtract nad automatic the varqty was appear as the result of subtration of input and output.


Thank you...

rhodarose
12-13-2010, 03:54 AM
this codes:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script type= "text/javascript">
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
var qty = new Array(2);
qty[0] = parseFloat(document.myform.inqty.value);
qty[1] = parseFloat(document.myform.outqty.value);

myqtyval = qty[0]-qty[1];
document.myform.myqty.value = myqtyval;
}

function stopCalc(){
clearInterval(interval);
}
</script>
</head>
<body>
<form name='myform' action='test.php' method='post'>
Input<input type='text' name='inqty' onFocus='startCalc();' onBlur='stopCalc();' />
Output<input type='text' name='outqty' onFocus='startCalc();' onBlur='stopCalc();' /><br/>
myqty<input type='text' name='myqty' value='' />
<input type='submit' name='submit' value='save' />


</form>
</body>
</html>


has the concept of what i want that after i insert number in output the result was automatically appear in qty but the problem in this code it did not use on key enter and I don't know how can i put that code n my php file where I attach.

I'm sorry, i do understand the concept but I don't know how can I code it and where i can put the codes.


Thank you..

Nile
12-14-2010, 01:47 AM
I don't know what to tell you - my script works fine in IE 8, IE 7, and FF with no errors for me.

jscheuer1
12-14-2010, 04:25 AM
I used this code:

<script type="text/javascript">
var c = document.getElementById('inqty');
var b = document.getElementById('outqty');
var a = document.getElementById('varqty');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>

Line: 38
Error: 'c' is null or not an object:confused:

You're not showing any element with an id of inqty. So probably it either hasn't been parsed yet by the browser at the point at which the code defines it:


var c = document.getElementById('inqty');

Or it doesn't exist. This could be due to page organization that's inadequate to this task and/or a typo and/or something else. But it could possibly be something else entirely. If you want more help on that error, to tell what's what -

We need you to put up a demo page that shows the error.

Otherwise we can only guess.

rhodarose
12-14-2010, 07:03 AM
You're not showing any element with an id of inqty. So probably it either hasn't been parsed yet by the browser at the point at which the code defines it:


var c = document.getElementById('inqty');

Or it doesn't exist. This could be due to page organization that's inadequate to this task and/or a typo and/or something else. But it could possibly be something else entirely. If you want more help on that error, to tell what's what -

We need you to put up a demo page that shows the error.

Otherwise we can only guess.

I put tthis code:



<script type="text/javascript">
var c = document.getElementById('inqty');
var b = document.getElementById('outqty');
var a = document.getElementById('varqty');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>


in my php codes but it did not work but no errors.

I attached my php codes.

Thank you

jscheuer1
12-14-2010, 07:31 AM
Move the highlighted:


. . . else
{
return true;
}
}
</script>

<script type="text/javascript">
var c = document.getElementById('inqty');
var b = document.getElementById('outqty');
var a = document.getElementById('varqty');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>
</head>
<body onLoad="document.clttype.clt_no.focus();">
<!--<p><a href="clt_definition.php">Clt Types</a>&nbsp;&nbsp;&nbsp;<a href="clt_query.php">Query</a></p>-->
<?php . . .

to:


. . . ut size='6' type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"saveform\");' /></td>";
echo "\n\t</tr>";
}
echo "</table>";
}
echo "<p><input type='submit' value=' Save ' id='saveform' /></p>";
echo "<input type='hidden' name='clt_typeno' value='" . $_POST["clt_typeno"] . "' />";
?>
</form>
<script type="text/javascript">
var c = document.getElementById('inqty');
var b = document.getElementById('outqty');
var a = document.getElementById('varqty');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>
</body>
</html>

If that doesn't fix it -

We need a link to the page, or any page that shows the error.

The only substitute that might work would be:


Load up the page that's giving you this error in the browser.


Use the browser's 'view source' to see the source code being served.


Select all and copy.


Paste that into a text file, save and attach that text file to a post here.

rhodarose
12-14-2010, 08:13 AM
Move the highlighted:


. . . else
{
return true;
}
}
</script>

<script type="text/javascript">
var c = document.getElementById('inqty');
var b = document.getElementById('outqty');
var a = document.getElementById('varqty');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>
</head>
<body onLoad="document.clttype.clt_no.focus();">
<!--<p><a href="clt_definition.php">Clt Types</a>&nbsp;&nbsp;&nbsp;<a href="clt_query.php">Query</a></p>-->
<?php . . .

to:


. . . ut size='6' type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"saveform\");' /></td>";
echo "\n\t</tr>";
}
echo "</table>";
}
echo "<p><input type='submit' value=' Save ' id='saveform' /></p>";
echo "<input type='hidden' name='clt_typeno' value='" . $_POST["clt_typeno"] . "' />";
?>
</form>
<script type="text/javascript">
var c = document.getElementById('inqty');
var b = document.getElementById('outqty');
var a = document.getElementById('varqty');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>
</body>
</html>

If that doesn't fix it -

We need a link to the page, or any page that shows the error.

The only substitute that might work would be:


Load up the page that's giving you this error in the browser.


Use the browser's 'view source' to see the source code being served.


Select all and copy.


Paste that into a text file, save and attach that text file to a post here.


i try what you said, but still it did not work, when i try to insert number in input and i press enter key and i insert number in ouput textfield and theres no output appear in varqty even I press enter key.

jscheuer1
12-14-2010, 04:11 PM
The script in question:


<script type="text/javascript">
var c = document.getElementById('inqty');
var b = document.getElementById('outqty');
var a = document.getElementById('varqty');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>

Isn't on the page in the zip attached to your post, and neither is any element with an id of "inqty". You do have id='inqty0' through id='inqty30' though.

I'd get rid of:


<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>

and the highlighted:


<body onLoad="document.clttype.clt_no.focus();">

and this (again highlighted) and all similar (there are tons of these, but probably not too many in the PHP file that created the file you sent):


<input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,"b3");' />

Add this script to the head:


<script type="text/javascript">
document.onkeypress = function(e){
e = e || event; e.returnValue = true;
var t = e.target || e.srcElement, re = /^(inqty|outqty)(\d+)$/, f = arguments.callee, m, i;
function next(){
if(!f.els && (m = t.form) === document.forms.clttype){
var ipts = m.getElementsByTagName('input'), els = []; i = ipts.length - 1;
for (i; i > -1; --i){
if(ipts[i].type && ipts[i].type.toLowerCase() === 'text'){
els.push(ipts[i]);
}
}
f.els = els;
}
if(f.els){
i = f.els.length - 1;
for (i; i > -1; --i){
if(f.els[i] === t && (m = f.els[i - 1])){
m.focus();
}
}
}
}
if((m = re.exec(t.id)) && e.keyCode === 13){
e.returnValue = false;
t.form.elements['varqty' + m[2]].value = t.form.elements['inqty' + m[2]].value - t.form.elements['outqty' + m[2]].value;
} else if (t.type && e.keyCode === 13 && t.type.toLowerCase() !== 'submit') {
e.returnValue = false;
}
if(!e.returnValue){
next();
if(e.preventDefault){e.preventDefault();}
}
return e.returnValue;
}
</script>

This will supply the functionality of both the removed script and the one Nile and you were trying to get to work. It automatically determines which field is next, and (in the case of subtraction) which fields to deal with. It doesn't matter how many or how few fields there are, as long as (again, only for subtraction) there are the three fields inqty#, outqty#, and varqty# for each number, 0 through however many. The body onLoad code pointed to a non-existent element, so was doing nothing other than throw an error. I'm thinking that you might want the subtraction activated differently though, other than just on hitting the ENTER key, and I wonder if subtraction is what's really required. But I leave both of those up to you to decide. Let me know if you need different or additional on that and want help implementing it.

rhodarose
12-15-2010, 12:10 AM
The script in question:


<script type="text/javascript">
var c = document.getElementById('inqty');
var b = document.getElementById('outqty');
var a = document.getElementById('varqty');
//define c, b, a

var performSubtract = function(e) {
var key = e ? e.which : window.event.keyCode; //get the key, 13 = ENTER
if(key == 13){
a.value = c.value - b.value; //subtract and set
}
};

c.onkeydown = b.onkeydown = performSubtract;
</script>

Isn't on the page in the zip attached to your post, and neither is any element with an id of "inqty". You do have id='inqty0' through id='inqty30' though.

I'd get rid of:


<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>

and the highlighted:


<body onLoad="document.clttype.clt_no.focus();">

and this (again highlighted) and all similar (there are tons of these, but probably not too many in the PHP file that created the file you sent):


<input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,"b3");' />

Add this script to the head:


<script type="text/javascript">
document.onkeypress = function(e){
e = e || event; e.returnValue = true;
var t = e.target || e.srcElement, re = /^(inqty|outqty)(\d+)$/, f = arguments.callee, m, i;
function next(){
if(!f.els && (m = t.form) === document.forms.clttype){
var ipts = m.getElementsByTagName('input'), els = []; i = ipts.length - 1;
for (i; i > -1; --i){
if(ipts[i].type && ipts[i].type.toLowerCase() === 'text'){
els.push(ipts[i]);
}
}
f.els = els;
}
if(f.els){
i = f.els.length - 1;
for (i; i > -1; --i){
if(f.els[i] === t && (m = f.els[i - 1])){
m.focus();
}
}
}
}
if((m = re.exec(t.id)) && e.keyCode === 13){
e.returnValue = false;
t.form.elements['varqty' + m[2]].value = t.form.elements['inqty' + m[2]].value - t.form.elements['outqty' + m[2]].value;
} else if (t.type && e.keyCode === 13 && t.type.toLowerCase() !== 'submit') {
e.returnValue = false;
}
if(!e.returnValue){
next();
if(e.preventDefault){e.preventDefault();}
}
return e.returnValue;
}
</script>

This will supply the functionality of both the removed script and the one Nile and you were trying to get to work. It automatically determines which field is next, and (in the case of subtraction) which fields to deal with. It doesn't matter how many or how few fields there are, as long as (again, only for subtraction) there are the three fields inqty#, outqty#, and varqty# for each number, 0 through however many. The body onLoad code pointed to a non-existent element, so was doing nothing other than throw an error. I'm thinking that you might want the subtraction activated differently though, other than just on hitting the ENTER key, and I wonder if subtraction is what's really required. But I leave both of those up to you to decide. Let me know if you need different or additional on that and want help implementing it.

You mean that if I used the code that you suggested I will removed those codes:



<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>
onLoad="document.clttype.clt_no.focus();"
onkeypress='return handleEnter(event,"b3");'



Thank you

jscheuer1
12-15-2010, 02:09 AM
That's what I said, yes.

rhodarose
12-15-2010, 02:13 AM
That's what I said, yes.


I will try and i will inform you..

Thank you very much

rhodarose
12-15-2010, 02:32 AM
That's what I said, yes.

It works but the result was appear in mc#
input qty output qty mc# varqty

the output was appear in mc# instead in varqty but the result was appear it is what I need. Thank you..

The only problem is the output was appear in mc# it should be in varqty

Thank you so much

jscheuer1
12-15-2010, 03:31 AM
That's just a layout problem. You must have changed your PHP such that the inputs with the id='varqty#', which is written in the PHP file as:


id='varqty" . $ctr . "'

now line up under the column in the table labeled MC #. In the zip file from your post #56 in this thread (which shows the HTML output of an earlier version of the PHP code), they line up under the proper column (VARIANCE Qty). Probably also in the txt file from your post #54 in this thread (which shows an earlier version of the PHP code), but I cannot be sure of that.

rhodarose
12-15-2010, 03:46 AM
That's just a layout problem. You must have changed your PHP such that the inputs with the id='varqty#', which is written in the PHP file as:


id='varqty" . $ctr . "'

now line up under the column in the table labeled MC #. In the zip file from your post #56 in this thread (which shows the HTML output of an earlier version of the PHP code), they line up under the proper column (VARIANCE Qty). Probably also in the txt file from your post #54 in this thread (which shows an earlier version of the PHP code), but I cannot be sure of that.

You mean in the code

id='varqty" . $ctr . "'
it should be:


id='inqty#'
id='outqty#'
id='varqty#'


I can't understand about the MC#, on how the result should be in variance qty.

jscheuer1
12-15-2010, 04:05 AM
An easy fix would be to just switch the two th elements in the PHP file here:


<th class='myclass'>MC #</th><th class='myclass'>VARIANCE Qty</th>

But then MC # heading or other column headings s might be in the wrong place. It's your layout, eventually you're going to have to understand it. Look at the source code in the browser like I said before using the browser's 'view source'. That may help you to understand how it's lining up.

Tables can be tricky to work with though. The only difference that jumps out at me from the old PHP code and the new that looks like it could be affecting this is here:


for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;
echo "\n\t<tr>";
echo "\n\t\t<td width='800'>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' /></td>";
echo "\n\t\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' ></td>";
echo "\n\t\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varsublot[]' id='varsublot" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" . $ctr . "' /></td>";
echo "\n\t</tr>";
}

In the old file it was:


for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;
echo "\n\t<tr>";
echo "\n\t\t<td width='800'>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' /></td>";
echo "\n\t\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' ></td>";
echo "\n\t\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varsublot[]' id='varsublot" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" . $ctr . "' /></td>";
echo "\n\t</tr>";
}

So you could either put that back, or if you don't need the MC #, leave it out and get rid of it here:


<th class='myclass'>MC #</th><th class='myclass'>VARIANCE Qty</th>

However, if there were errors before that you didn't see, they may still exist. You see, the headings need to line up each with their respective columns of inputs. If they don't, then submitting the form may have different reults than intended. You won't be able to tell that until you do a few test submissions and see what data gets passed along or stored.

rhodarose
12-15-2010, 04:50 AM
An easy fix would be to just switch the two th elements in the PHP file here:


<th class='myclass'>MC #</th><th class='myclass'>VARIANCE Qty</th>

But then MC # heading or other column headings s might be in the wrong place. It's your layout, eventually you're going to have to understand it. Look at the source code in the browser like I said before using the browser's 'view source'. That may help you to understand how it's lining up.

Tables can be tricky to work with though. The only difference that jumps out at me from the old PHP code and the new that looks like it could be affecting this is here:


for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;
echo "\n\t<tr>";
echo "\n\t\t<td width='800'>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' /></td>";
echo "\n\t\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' ></td>";
echo "\n\t\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varsublot[]' id='varsublot" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" . $ctr . "' /></td>";
echo "\n\t</tr>";
}

In the old file it was:


for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;
echo "\n\t<tr>";
echo "\n\t\t<td width='800'>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' /></td>";
echo "\n\t\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' ></td>";
echo "\n\t\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varsublot[]' id='varsublot" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" . $ctr . "' /></td>";
echo "\n\t</tr>";
}

So you could either put that back, or if you don't need the MC #, leave it out and get rid of it here:


<th class='myclass'>MC #</th><th class='myclass'>VARIANCE Qty</th>

However, if there were errors before that you didn't see, they may still exist. You see, the headings need to line up each with their respective columns of inputs. If they don't, then submitting the form may have different reults than intended. You won't be able to tell that until you do a few test submissions and see what data gets passed along or stored.

input_qty input_unit(fix) output_qty output_unit(fix) id# mc# varqty

why is it the output is being appeared in mc# ?

Thank you

rhodarose
12-15-2010, 04:57 AM
I fix it but adding



echo "\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" . $ctr . "' /></td>";


Thank you so much

can you give the explanation of the code that you given

Thank you

rhodarose
12-15-2010, 05:08 AM
Can you visit my other post about the sum of operation2 input qty and the result will be appear in input qty in operation2_total, because it is in the same code where i post here.

Thank you

jscheuer1
12-15-2010, 06:15 AM
I fix it but adding



echo "\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" . $ctr . "' /></td>";


Thank you so much

can you give the explanation of the code that you given

Thank you

Well, it's your own code. It was in the file that was 'working' before, but not in the one that wasn't. It puts another column in the table. Everything in that block of echo commands:


for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;
echo "\n\t<tr>";
echo "\n\t\t<td width='800'>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' /></td>";
echo "\n\t\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' ></td>";
echo "\n\t\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varsublot[]' id='varsublot" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" . $ctr . "' /></td>";
echo "\n\t</tr>";
}

gets output (echoed) for each $trows. It (combined with the other code) creates a section of a table.

rhodarose
12-15-2010, 06:23 AM
Well, it's your own code. It was in the file that was 'working' before, but not in the one that wasn't. It puts another column in the table. Everything in that block of echo commands:


for($ctr = 0; $ctr < $trows; $ctr++)
{
$row = mysql_fetch_array($result);
$tctr = $ctr + 1;
echo "\n\t<tr>";
echo "\n\t\t<td width='800'>";
if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
$last_operation_name = $row["operation_name"];
echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' /></td>";
echo "\n\t\t<td>" . $row["input_unit"];
echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' ></td>";
echo "\n\t\t<td>" . $row["output_unit"];
echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
echo "\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='varsublot[]' id='varsublot" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" . $ctr . "' /></td>";
echo "\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" . $ctr . "' /></td>";
echo "\n\t</tr>";
}

gets output (echoed) for each $trows. It (combined with the other code) creates a section of a table.

what I mean is can you explain the code that you given:


<script type="text/javascript">
document.onkeypress = function(e){
e = e || event; e.returnValue = true;
var t = e.target || e.srcElement, re = /^(inqty|outqty)(\d+)$/, f = arguments.callee, m, i;
function next(){
if(!f.els && (m = t.form) === document.forms.clttype){
var ipts = m.getElementsByTagName('input'), els = []; i = ipts.length - 1;
for (i; i > -1; --i){
if(ipts[i].type && ipts[i].type.toLowerCase() === 'text'){
els.push(ipts[i]);
}
}
f.els = els;
}
if(f.els){
i = f.els.length - 1;
for (i; i > -1; --i){
if(f.els[i] === t && (m = f.els[i - 1])){
m.focus();
}
}
}
}
if((m = re.exec(t.id)) && e.keyCode === 13){
e.returnValue = false;
t.form.elements['varqty' + m[2]].value = t.form.elements['inqty' + m[2]].value - t.form.elements['outqty' + m[2]].value;
} else if (t.type && e.keyCode === 13 && t.type.toLowerCase() !== 'submit') {
e.returnValue = false;
}
if(!e.returnValue){
next();
if(e.preventDefault){e.preventDefault();}
}
return e.returnValue;
}
</script>


Thank you

jscheuer1
12-15-2010, 03:41 PM
Please stop quoting everything I type!

Here's an annotated version of the function:


<script type="text/javascript">
document.onkeypress = function(e){ // Listens for any keypress for the entire document and gets a reference for the event (e)
// for IE e will be null, if so set it to the global event; set the returnValue to true for now
// e.returnValue has special meaning in IE, and is a valid arbitrary flag in all others:
e = e || event; e.returnValue = true;
// set some variables local to this function - t will be the element that received the keypress event,
// re will be a regular expression used later to determine if inqty# or outqty# were the
// id of the element and to capture the # part if so,
// f becomes a reference to this function, m & i are set as local variables for later use
// f is shorthand for the function, m is shorthad for match, i for item:
var t = e.target || e.srcElement, re = /^(inqty|outqty)(\d+)$/, f = arguments.callee, m, i;
// defines a function next() for later use locally within the keypress function
// when the key is ENTER and certain other conditions (described below) are satisfied:
function next(){
// if we haven't got the array of input elements for this form yet and this form is
// the form with the name clttype, set m (from the above) = to the form for now
// and execute the following bracketed code block.
// f.els is a property we created or will create of the keypress function,
// t.form is the parent form if any of the element that received the keypress
// document.forms.clttype is a reference to the particular form we are interested in:
if(!f.els && (m = t.form) === document.forms.clttype){
// set some variables local to the next() function
// ipts will be all input elements in the form clttype, els will be
// an empty array. Also set i (from above) to the number of inputs for now:
var ipts = m.getElementsByTagName('input'), els = []; i = ipts.length - 1;
for (i; i > -1; --i){ // for each input in the form
if(ipts[i].type && ipts[i].type.toLowerCase() === 'text'){ // if it's a text input
els.push(ipts[i]); // add it to the els array
}
}
f.els = els; // set the globally accessible f.els to the finished array of text inputs
}
if(f.els){ // if we already had the array of text inputs or just created it
i = f.els.length - 1; // set i equal to the number of text inputs for now
for (i; i > -1; --i){ // for each text input
// if this is the one keypressed & there's one that follows it
// set m (from above) to the one that follows it for now:
if(f.els[i] === t && (m = f.els[i - 1])){
m.focus(); // and give the one that follows it focus
}
}
}
} // end next() function
// if the element keypressed has an id of inqty# or outqty# & the key was ENTER
// set m (from above) to an array whose [2] index is the # part of that for now,
// and do the next bracketed block:
if((m = re.exec(t.id)) && e.keyCode === 13){
e.returnValue = false; // for IE this function will now return false when it ends. All others - this is a flag for later use
// with the reference we have to the # part of the element keypressed, perform the subtraction & output
// the result to the varqty# id element:
t.form.elements['varqty' + m[2]].value = t.form.elements['inqty' + m[2]].value - t.form.elements['outqty' + m[2]].value;
// if the input keypressed was not inqty# or outqty# and not the submit button and the key was ENTER
// execute the following bracketed code block:
} else if (t.type && e.keyCode === 13 && t.type.toLowerCase() !== 'submit') {
// for IE this function will now return false (cancel the default action) when it ends.
// All others and IE - this is a flag for later use:
e.returnValue = false;
}
if(!e.returnValue){ // if our flag is false (this includes IE and all others) execute the following bracketed code
next(); // highlight the next text input if any (see next() function above for details)
// if the browser supports canceling the default action of the keypress
// with the preventDefault method, do so:
if(e.preventDefault){e.preventDefault();}
}
// probably meaningless at this point, but if some browser doesn't yet know what to return
// and therefore what to do with the default action of the keypress, this will tell it:
return e.returnValue;
}
</script>

rhodarose
12-16-2010, 03:05 AM
is it my problem in summation of input of operation2 and the result will be appear in operation2_total input? will be resolved by using the code that you given.?

the you given is amazing and I never think that that code is the solution, honestly now I can't code the code you given.


Did you see my other thread about sum?

Thank you

jscheuer1
12-16-2010, 08:04 AM
I did have a look at this thread:

http://www.dynamicdrive.com/forums/showthread.php?p=243404#post243404

If that's the one you mean, I'm not sure if I can help with that. I've never used mysql_query() and don't know what comes back from it. I imagine it would vary depending upon what's in the database. I have no idea what format the response would take. PHP in general isn't my strong point. I'm even weaker in MySQL. I don't see where anything is used in that thread or its attachments that attempts to do any kind of mathematic addition other than increasing incrementally the $ctr variable.

If you're looking for a javascript solution, I might be able to help. One thing you should know about javascript though, and this applies to what I've contributed in this thread as well, is that if the user has javascript disabled, none of the javascript stuff will work.

This is unlike PHP where all browsers see the same thing more or less regardless of their settings. But if you want to do your math in PHP and it involves input from the user, the user must submit a form with their input before PHP can have access to any input from them. Javascript could perform an assist here by sending new information to and fetching the results from the server via AJAX. That could make submitting a form unnecessary except for folks with javascript unavailable.

But that's not what the javascript offered by me in this thread does. It's wholly dependent upon the user's browser.

To do what I propose is pretty complicated though and a bit outside the purposes of this forum. You'd be better off with a paid technician and/or some sort of CMS.

rhodarose
12-17-2010, 12:38 AM
I attached the image of my form.

Thank you

rhodarose
12-17-2010, 02:22 AM
I think is not possible to happen what i want using php code.I am right?because it's too complicated.