473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Simple form to add numbers

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 7553
sanjib65
102 100+
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 Expert 2GB
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
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...
3
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...
1
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...
2
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...
7
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...
18
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...
24
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...
5
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...
7
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...

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.