Jump to content

[SOLVED] Looping through array of form elements with same name prefix


jwwceo

Recommended Posts

Hello,

 

I am writing a payment commission reconciling script, in php, but I would also like the commission totals to update on the page using javascript. I am uncertain of the syntax to grab an array of form elements, all having the same name. Here is my html data, where K is the payment id

<td><input type='hidden' name='payment[{$k.paymentid}][total]' value='{$k.amount}'></td>
<td><input type='text' name='payment[{$k.paymentid}][commission]' value='.185'></td>
<td><input type='text' name='payment[{$k.paymentid}][expenses]' value='0.00'></td>
<td><input type='checkbox' name='payment[{$k.paymentid}][pay]' value='Y'></td>

 

I would like grab these values, in javascript and lop through them, and display the commission due, as the figures are typed in.

 

I have tried this:

 

<script type="text/javascript">
function getElements()
  {
  var x=document.getElementsByName("payment[][]");
  alert(x.length);
  }
</script>

 

just to test if the array of items is being pulled in, and it shows 0 items.

 

Any ideas.

 

James

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.