How to add the two input number using Jquery ?


Hi

So many time while working with Jquery, you will think, how can i do the summation of two number using Jquery. Here is the simple syntax for doing this task.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../../Scripts/jquery.min.js"></script>
    <script>
        $(function () {
            $("#btnSum").click(function () {
                 var res = (parseInt($("#Num1").val()) + parseInt($("#Num2").val()));
                alert(res);
            });
            
        });
    </script>
</head>
<body>
   Num1: <input type="text" name="Num1" id="Num1" value="" />
    <br />
    Num2 :<input type="text" name="Num2" id="Num2" value="" />
    <br />
    <button id="btnSum">Click Here</button>
</body>
</html>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: