473,804 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple form to add numbers

1 New Member
The code below accepts two numbers from textboxes and should show the addition in the third one.I can t figure out how to display addition in the third text box...
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <form action="addition_n.asp" method="post">
  5. First number:&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="no1" size="20" />
  6. &nbsp;
  7. <p>
  8. Second number: <input type="text" name="no2" size="20" value="5" />
  9. &nbsp;</p>
  10. <p>
  11.  
  12.  Addition:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="no3" size="20"/>
  13. </p>
  14. <p>&nbsp;
  15. <input type="submit" value="Submit" onclick="call add()" />
  16. </p>
  17.  
  18. <%
  19. sub add()
  20. dim n1,n2,n3 
  21. n1=cint(Request.form("no1"))
  22. n2=cint(Request.form("no2"))
  23. n3=n1+n2
  24. Response.write(n3)
  25. end sub
  26.  
  27. call add()
  28. %>
  29.  
  30. </form>
  31.  
  32. </body>
  33. </html>
Dec 18 '09 #1
2 7643
sanjib65
102 New Member
Sorry I can't display it VB.NET but in C# it's done this way

Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.         int i = 0;
  4.         i = Convert.ToInt32(TextBox1.Text) + Convert.ToInt32(TextBox2.Text);
  5.         TextBox3.Text = i.ToString();
  6.     }
Dec 19 '09 #2
jhardman
3,406 Recognized Expert Specialist
The big problem is that the ASP is executed on the server before it is sent to the browser, but your call is executed when the user clicks the button. The server will never execute the function, because IT ALREADY FINISHED EXECUTING ALL OF THE ASP CODE. If you want it done on the browser, you will need to use a client-side technology, like javascript. Otherwise, try it like this:
Expand|Select|Wrap|Line Numbers
  1. <form method="post" action="thisPage.asp">
  2. <input type="text" name="n1" value="<%=request.form("n1")%>">
  3. <input type="text" name="n2" value="<%=request.form("n2")%>">
  4. <%
  5. dim n3
  6. n3 = 0
  7. if request.form("n1") <> "" AND request.form("n2") <> "" then
  8.    n3 = cint(request.form("n1") + request.form("n2")
  9. end if
  10. <input type="text" name="n3" value="<%=n3%>">
  11. <input type="submit" name="submit" value="Add">
  12. </form>
this method submits the form back to the server, the server looks it over and refills the form with the original inputs, and performs the addition, before sending the form back to the client. Does this make sense?

Jared
Dec 22 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
2547
by: greg.scharlemann | last post by:
I've been playing with this form validation method for a while and have tried an array of things but haven't had any luck with a couple items. 1. The validateForm() function doesn't detect when the Min price is greater than the maximum price. 2. The validateForm() function doesn't call isNumber() on the minBaths, maxBaths, minBeds, or maxBeds. 3. Despite errors in input and the validateForm() function returning false, the form is still...
3
2174
by: Iain Miller | last post by:
Can anybody help me with some Access 2000 code? I don't do a lot of coding in Access & so every time I come back to do something I pretty much have to relearn the syntax from scratch so this is taking me hours. As with most occasional programmers its the commas, colons, inverted commas, square brackets etc etc that cause the problem! (Not to mention the nuances of using Do While, Do until, Case statements If statements, IIF etc etc...)...
1
3278
by: Shannan Casteel via AccessMonster.com | last post by:
If I had 2 tables, one that displayed ClaimNo, PartNo, and Quantity, and another that just has PartNo and Quantity, how could I get Access to search for the PartNo in table 2 that was entered in table 1, then if it found it add the associated quantity to table 2 from table 1, and if it is not found to add it, with its associated quantity to table 2. This should be simple.....its just a running total/tally.... Table 1 ClaimNo ...
2
8407
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
7
1783
by: Trickynick1001 | last post by:
Hi, a newbie here. I don't have a real firm grasp on the idea of Javascript, as I'm used to programming in Qbasic and C. I'm not used to OOP. Anyway, I really don't have any idea what the problem is with this code, it just simply won't work properly. Some of the functions aren't done, but the main one gives me a Not a Number message in the text box where the calculations are supposed to come up. I tried to use a parseInt on my stuff,...
18
1926
by: Bob Cummings | last post by:
Not sure if this is the correct place or not. Anyhow in school we were taught that when trying to calculate the efficiency of an algorithm to focus on something called FLOPs or Floating Point operations and disregard all integer operations. My question is this. I am writing a simulation for animal dispersement through large landscapes. We are loading data from several different files to simulate the environment the animals will be...
24
6348
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to have on his site, a Javascript Calculator for working out the cost of what they want, for example: 1 widget and 2 widglets = £5.00
5
2190
Cowbie
by: Cowbie | last post by:
Hello everyone, I'm very new to PHP and I'm keen to learn how it all works. I've been looking for help all day and reading tutorials etc which is how I came accross this forum - so here's hoping for some answers :) First off I'll tell you what I'm doing. I'm making a calculator of some form which will do some simple calculations on the numbers entered into a form. For example, adding, multiplying etc. At the moment just to get me going I...
7
1198
by: bvdp | last post by:
Is there a simple/safe expression evaluator I can use in a python program. I just want to pass along a string in the form "1 + 44 / 3" or perhaps "1 + (-4.3*5)" and get a numeric result. I can do this with eval() but I really don't want to subject my users to the problems with that method. In this use I don't need python to worry about complex numbers, variables or anything else. Just do the math on a set of values. Would eval() with...
1
2077
by: astrogirl77 | last post by:
I'm new to C++ and am hoping to find help with coding a simple C program, am wanting to obtain code and functioning exe's. I code in an old version of Visual Basic 4.0, I have a simple app that is about 3 and a half pages of code long it does some relatively simple math additions and subtractions The problem I have is that some numbers get to be very large integers and VB automatically converts this to scientifc notation, what I need is...
0
10599
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10346
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10347
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.