adding numeric values of variable number of forms

I'm trying to use jquery to loop through a block of forms that contain numeric data and add it all up to be displayed in a form with id grand. I have the ability to dynamically add new forms, so the number of forms I'm looping through will change. Here's my jquery code I wrote that isn't working for whatever reason:

$('#table').delegate('input#grand', 'focus', function(){
var grand = $(input.expend).map(function(){
  return this.value;
});
$(grand).each(function(){
  var g = 0;
  g+= $(this);
  $('input#grand').val(g);
});

});

Answers


In my example, I'm using a table with the ID of "table" as the container for the input elements, but you can use whatever you want:

    <script type="text/javascript">
        $(document).ready(function () {
            $("#table input").change(function () {
                var total = 0;
                $("#table input").each(function (index, item) {
                    var value = parseFloat($(item).val());
                    if (!isNaN(value)) {
                        total += value;
                    }
                });
                $("#grand").val(total);
            });
        });
    </script>

    <table id="table">
        <tr>
            <td>
                <input />
            </td>
        </tr>
        // more inputs
    </table>
    <input id="grand" />

Need Your Help

Downgrade Subversion 1.8 working copy to 1.7

macos svn

Has anybody already managed to downgrade from Subversion 1.8 to Subversion 1.7? The provided script at http://svn.apache.org/repos/asf/subversion/trunk/tools/client-side/change-svn-wc-format.py only

GWT java.io.File server package

java file gwt smartgwt java-io

I was looking for hours now, but I can't find what I'm looking for. I know java.io.File is not supported in the GWT client package. I want to use it inside the server package. When I compile the ap...