Link to home
Create AccountLog in
Avatar of n00b0101
n00b0101

asked on

jquery: summing dynamic elements?

I have a form, where, once you begin to add text, another row beneath it will appear.  (The code for that is below).  I'm trying to figure out how to sum these values on input as they're added?  
// this is the jquery that appends a row
$( function(){
        $("#dnotes > tbody > tr > td > input").bind('focus', function(){
                        var row = $(this).closest("tr").get(0);
                        if( row.className.indexOf("clicked")==-1 )
                        {       
                                var rowCopy=$(row).clone(true);
                                $(row).closest("tbody").append(rowCopy);
                                row.className+="clicked";
                                var newInput=$("input",rowCopy).get(0);
                                newInput.id="newId";
                                $(newInput).bind('focus',attachAutoCompleteEEValues);
                        }
        });
});
 
// this is the accompanying html
<tr>
<td><input type="text" id="diningroomemployee" name="drlabor[employee][]" /></td>
<td><input type="text" name="drlabor[othours][]" value=""  /></td>
<td><input type="text" name="drlabor[dthours][]" value=""  /></td>
<td><input type="text" name="drlabor[break][]" value="" /></td>
<td><input type="text" name="drlabor[shift][]" value="" class="standardTextfieldSmall" /></td>
</tr>
 
// this is where I want to put the totals for drlabor[othours][], etc.
<tr>
<td id="totalothours"></td>
<td id="totaldthours"></td>
<td id="totalbreak"></td>
<td id="totalshift"></td>
</tr>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account