CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Math operations in an ONCHANGE event

Print topic Send  topic

Author Message
jsmonkey


Posts: 39
Posted: 07/07/2010, 11:34 AM

I want to do some math in an ASP page. Something like this:

User enters number in Textbox1 then Textbox2 and an ONCHANGE event adds (or other operator) the values into Textbox3. Textbox3's computed value get written to the database.


Can you help point me in the right coding direction? ANY advice will help... inheritied a project here and I am at wall.
_________________
-J
View profile  Send private message
lboeldt

Posts: 53
Posted: 07/07/2010, 12:41 PM

Hi JSMonkey,

Make sure the ID of each textbox is set to TextBox1, TextBox2, TextBox3 to match the field's name.

In your header check to make sure prototype.js is included in a script tag if not place the following tag just below the <head> tag.

  
<script language="javascript" src="/js/pt/prototype.js"></script>  
  
<script language="javascript>  
function recalcTextBoxes() {  
   // Make sure both boxes have a value  
   if  ( ( $("TextBox1").value != "" ) && ( $("TextBox2").value!="" ) {  
        // if both boxes have a value calculate for box 3  
         $("TextBox3").value=$("TextBox1").value+$("TextBox2").value  
   }  
}  
</script>  

Put recalcTextBoxes in the on change event for textbox1 and textbox2.


When either box changes the new total is re-calculated provided both boxes are filled.

Let me know if this helps. If this fulfills your request, please mark this thread as resolved by adding [resolved] to the title. Thanks.
View profile  Send private message
jsmonkey


Posts: 39
Posted: 07/08/2010, 11:16 AM

Thanks for pointing the way! I had a couple of bumps but now I get 1+2 = 12. I know Javascript handles strings strangely... please help.



Here is my page:

  
<head>    
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">    
<title>MathPage_TEST1</title>    
<meta name="GENERATOR" content="CodeCharge Studio 4.3.00.7676">    
  
  
<script language="javascript" src="prototype.js"></script>    
    
<script language="javascript">    
function recalcTextBoxes() {    
   // Make sure both boxes have a value    
   if  ( ( $("TextBox1").value != "" ) && ( $("TextBox2").value!="" )) {    
        // if both boxes have a value calculate for box 3    
         $("TextBox3").value=$("TextBox1").value+$("TextBox2").value 		   
   }    
}    
</script>    
  
  
    
</head>    
<body>    
<input id="Textbox1" onchange="recalcTextBoxes();" name="Textbox1"><input id="Textbox2"   
  
onchange="recalcTextBoxes();" name="Textbox2"><input id="Textbox3" name="Textbox3">    
</body>    
</html>  
  
  
  
 
                  
_________________
-J
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.