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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.