Addition of two numbers with java script

In this article I am going to show how to add 2 numeric numbers using java script:

<head runat="server">
    <title></title>
  
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
  
    <script type="text/javascript">
        $(function() {
            $('#btnAdd').click(function() {
                var value1 = $('#txtFirstNumber').val();
                var value2 = $('#txtSecondNumber').val();
                var sum = parseInt(value1, 10) + parseInt(value2, 10);
                $('#msg').html(sum);
            });
        });
    </script>
  
</head>
<body>
    <form id="form1" runat="server">
    First Number :<input id="txtFirstNumber" type="text" /><br />
    Second Number:<input id="txtSecondNumber" type="text" />
    <input id="btnAdd" type="button" value="Add"  />
    <br />
    <span id="msg"></span>
    </form>
</body>
</html>

About Author

Written By Lavish Kumar

Based out of New York, USA, Lavish Kumar is a full stack web developer by profession and founder of Striving Programmers, a trusted community for developers that offers a wealth of articles and forums to assist individuals with improving their software development skills.

Leave your comment
Comments
10/23/2014 4:36 AM
tanQ
10/23/2014 4:36 AM
tanQ