Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    dynamic text boxes

    Hey,

    I have 3 textboxes which numbers are entered into. Each time a value in any of these changes, I want to add up the total of the 3 boxes and display this (preferably in a non-editable fashion) before clicking my submit button to pass this and other information to the next page.

    How to I do this? All advice welcome thanks

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    I would use client side javascript

    Code:
    <html>
    <head>
    <title></title>
    <script type="text/javascript">
    <!--
    
    function getSums(a,b,c){
    	var fields = document.thisForm;
    	var a = fields.a.value;
    	var b = fields.b.value;
    	var c = fields.c.value;	
    	if(!a){
    		a = 0;
    	}else{ 
    		a = parseFloat(a);
    	}if(!b){
    		b = 0;
    	}else{ 
    		b = parseFloat(b);
    	}
    	if(!c){
    		c = 0;
    	}else{ 
    		c = parseFloat(c);
    	}
    	var total = a + b + c;
    	fields.sum.value = total;	
    }
    //-->
    </script>
    </head>
    <body>
    <form name="thisForm">
    &nbsp;&nbsp; <input name="a" onBlur="getSums()"> <br>
    + <input name="b" onChange="getSums()"><br>
    + <input name="c" onChange="getSums()"><br> 
    = <input name="sum" readonly>
    </form>
    
    </body>
    </html>


  •  

    Posting Permissions

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