posted 12/27/2009 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>
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18