Who is online? 160 guests and 0 members
Member login | Become a member
posted 12/27/2009 1:53:51 PM by raghav_khunger
In this blog i will show how to add two numbers with javascript. I have used parseInt function to convert the value from string to int.Below is the sample code:
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> First Number :<input id="txtFirstNumber" type="text" /><br /> Second Number:<input id="txtSecondNumber" type="text" /> <input id="btnAdd" type="button" value="Add" onclick="sum();" /> </body> <script type="text/javascript"> function sum() { var txtFirstNumberValue = document.getElementById('txtFirstNumber').value; var txtSecondNumberValue = document.getElementById('txtSecondNumber').value; alert(parseInt(txtFirstNumberValue) + parseInt(txtSecondNumberValue)); } </script> </html>
raghav_khunger (Member since: 4/19/2009 1:46:52 AM)
View raghav_khunger 's profile
Leave a comment
It's fast, easy and free! Submit articles, get your own blog, ask questions & give answers in the forums, and become a better developer, faster.
enter your email address: