Page 6 of 8 FirstFirst ... 45678 LastLast
Results 51 to 60 of 74

Thread: Problem in Subtraction

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

    Default

    this codes:
    HTML Code:
    <!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..

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

    Default

    I don't know what to tell you - my script works fine in IE 8, IE 7, and FF with no errors for me.
    Jeremy | jfein.net

  3. #53
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

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

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

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Nile (12-14-2010)

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

    Default

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

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

    HTML 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

  6. #55
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Move the highlighted:

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

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

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

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

    3. Select all and copy.

    4. Paste that into a text file, save and attach that text file to a post here.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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

    Default

    Quote Originally Posted by jscheuer1 View Post
    Move the highlighted:

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

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

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

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

    3. Select all and copy.

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

  8. #57
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The script in question:

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

    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>
    and the highlighted:

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

    Code:
    <input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,"b3");' />
    Add this script to the head:

    Code:
    <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.
    Last edited by jscheuer1; 12-14-2010 at 06:26 PM. Reason: minor code improvements
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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

    Default

    Quote Originally Posted by jscheuer1 View Post
    The script in question:

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

    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>
    and the highlighted:

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

    Code:
    <input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,"b3");' />
    Add this script to the head:

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

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

  10. #59
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That's what I said, yes.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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

    Default

    Quote Originally Posted by jscheuer1 View Post
    That's what I said, yes.

    I will try and i will inform you..

    Thank you very much

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
  •