Page 3 of 8 FirstFirst 12345 ... LastLast
Results 21 to 30 of 74

Thread: Problem in Subtraction

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

    Default

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

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

    Default

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

    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:

    PHP 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 language="javascript">
        function 
    handleEnter(enextfield)
            {
            var 
    characterCode = (&& e.which)? e.whiche.keyCode;
            if(
    characterCode == 13)
                {
                
    document.getElementById(nextfield).focus();
                return 
    false;
                } 
            else
                {
                return 
    true;
                }
            }
        
    </script> 
    Last edited by rhodarose; 12-10-2010 at 02:56 AM.

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

    Default

    my webpage was on localhost

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

    Default

    I'm sorry, because I'm not good in codeing and analyzing..I really need to fix this problem..

    Thank you

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

    Default

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

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

    Default

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

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

    Default

    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

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

    Default

    It should be like this:
    Code:
    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.
    Jeremy | jfein.net

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

    Default

    Quote Originally Posted by Nile View Post
    It should be like this:
    Code:
    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

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

    Default

    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>
    Last edited by Nile; 12-10-2010 at 09:33 PM.
    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
  •