Question : Looping through rows of controls

I could potentially have multiple rows.  On each row I have a checkbox, label and textbox.  Each control is named dynamically.  For example each control has basically the same name:

CheckboxApplyTo
txtAmountPaid
lblOrigAmount

at then end of each control name I add a claimId.

CheckboxApplyTo554423
txtAmountPaid554423
lblOrigAmount554423

CheckboxApplyTo345612
txtAmountPaid345612
lblOrigAmount345612

etc...

How do I loop through all the txtAmountPaid fields so I can set the value to ''?

I know how to do it if I didn't use a claimId and just used 1, 2, 3...

1:
2:
3:
4:
for (var i = 1; i < rowCount; i++)
{
  document.getElementById('txtAmountPaid' + [i].value = '';
}

Answer : Looping through rows of controls

This is how I completed this:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
$(document).ready(function(){    
          $(".text").change(function(event)
            {
                txtBoxCalcAmtPaid();
            });
    });
    
    function txtBoxCalcAmtPaid(){        
        //When the user changes the amount due the checked line items are added to the 'Payment Amount' textbox
        var sum = 0;
        $.each($(".check"), function(i,v) 
        {
            var theElement = $(v);
            if(v.checked)
            {
                var theValue = theElement.val();
                sum += parseFloat(document.getElementById("txtAmountPaid" + theValue).value);
            }
            else
            {
                //clear the txtAmountPaid field if the checkbox is not checked
                var theValue = theElement.val();
                document.getElementById("txtAmountPaid" + theValue).value = '';
            }
        });
        document.getElementById("txtPaymentAmt").value = FormatCurrency(sum);
    }
Random Solutions  
 
programming4us programming4us