Dec 31, 2011

Sum of two Textbox values into third Textbox using JQuery

A script that sums up two textbox values using jQuery. **Note that I am not using any validation for textbox values.
<html xmlns="">
<head runat="server">
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        $(function () {
            var textBox1 = $('input:text[id$=TextBox1]').keyup(foo);
            var textBox2 = $('input:text[id$=TextBox2]').keyup(foo);            
            function foo() {
                var value1 = textBox1.val();
                var value2 = textBox2.val();               
                var sum = add(value1, value2);
            function add() {
                var sum = 0;
                for (var i = 0, j = arguments.length; i < j; i++) {
                    if (IsNumeric(arguments[i])) {
                        sum += parseFloat(arguments[i]);
                return sum;
            function IsNumeric(input) {
                return (input - 0) == input && input.length > 0;
    <form id="form1" runat="server">
    <table width="300px" border="1" style="border-collapse:collapse;background-color:#E8DCFF">
        <td> <asp:TextBox runat="server" ID="TextBox1"></asp:TextBox></td>
    <asp:TextBox runat="server" ID="TextBox2"></asp:TextBox>
    <asp:TextBox runat="server" ID="TextBox3"></asp:TextBox>
Output will be as:


sssssssdsd sdsdsdsdsdsdsd

Post a Comment

Your comments:


Twitter Delicious Facebook Digg Stumbleupon Favorites More