Page 2 of 8 FirstFirst 1234 ... LastLast
Results 11 to 20 of 74

Thread: Problem in Subtraction

  1. #11
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nile View Post
    Please dont double post.
    Code:
    <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:

    Code:
      <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.

  2. #12
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I dont understand? Just play around with my code..
    Jeremy | jfein.net

  3. #13
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    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

  4. #14
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nile View Post
    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.

  5. #15
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Copy and paste my code where you want it and use it accordingly
    Jeremy | jfein.net

  6. #16
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nile View Post
    I dont understand? Just play around with my code..
    Did you see my previous post, my webpage code?

  7. #17
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Yes, I did. If my code above was not what you wanted could you explain it in different words?
    Jeremy | jfein.net

  8. #18
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nile View Post
    Copy and paste my code where you want it and use it accordingly
    PHP Code:
    <?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

  9. #19
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    What was the error displayed?
    Jeremy | jfein.net

  10. #20
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Nile View Post
    What was the error displayed?
    here is the error
    Line: 31
    Error: 'document.getElementById(...)' is null or not an object

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •