Page 4 of 8 FirstFirst ... 23456 ... LastLast
Results 31 to 40 of 74

Thread: Problem in Subtraction

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

    Default

    Quote Originally Posted by Nile View Post
    This should do it:
    Code:
    <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

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

    Default

    this code is for subtraction of input and output using javascript
    Code:
    <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>

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

    Default

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

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

    Default

    Code:
    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>
    Jeremy | jfein.net

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

    Default

    Quote Originally Posted by Nile View Post
    Code:
    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 ?

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

    Default

    Yes? Use this code..
    Jeremy | jfein.net

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

    Default

    Quote Originally Posted by Nile View Post
    Yes? Use this code..
    Is it I will change the abc into inqty,outqrty,qty?

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

    Default

    If you cant change the IDs to abc, change the code:
    Code:
    var c = document.getElementById('c');
    var b = document.getElementById('b');
    var a = document.getElementById('a');
    And replace the highlighted with your ID
    Jeremy | jfein.net

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

    Default

    Quote Originally Posted by Nile View Post
    If you cant change the IDs to abc, change the code:
    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:

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

    Default

    Are you putting this under your input types? What browser?
    Jeremy | jfein.net

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
  •