I have 2 text fields , i want to add the value of the two text fields and show the sum on the third field on onclick. But my problem is field name and id is an array.

The form name is useless and misleading. Make it an id attribute instead, and your scripting will be able to more easily work with the elements of the form.Typically this is done by using the name attribute to name the fields of the form that you intend to submit.

The benefit of doing things this way, is that the only possible conflicting part of the form is now the single id attribute on the form tag, which should be a different identifier on a different form anyway to represent what it is that the form does.

var form = document.getElementById('mpr_audit');

Now that you have a reference to the form, you can easily access the named elements within it by using the elements collection:

<table width="100%" border="0" cellspacing="3" cellpadding="2"> <tr> <td rowspan="2"><strong>Type Of The Societies , Directorate Wise</strong></td> <td rowspan="2"><strong>Amount Of Audit Fees Outstanding At The Beginning Of The Year</strong></td> <td rowspan="2"><strong>Amount Of Audit Fees Levied Up To The Beginning Of The Month</strong></td> <td rowspan="2"><strong>Amount Of Audit Fees Levied During the d_month</strong></td> <td rowspan="2"><strong>Total Amount Of Audit Fees Levied From The Beginning Of The Year Till End Of The Month</strong></td> <td rowspan="2"><strong>Total Demand For Collection</strong></td>

I wrote the code but it is not working due to while loop.. so plz tell me how to do that

Paul_Wilkins
—
2012-03-07T05:55:00Z —
#4

lee_help said:

I wrote the code but it is not working due to while loop.. so plz tell me how to do that

The easiest way would be to loop through the entire form, adding up form.elements['outstanding_fees[]'][i] and form.elements['levied_fees[]'][i] and other associated fields, assigning the result to form.elements['total_amt_levied_fees[]'][i]