jwwceo Posted July 28, 2009 Share Posted July 28, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/167742-solved-looping-through-array-of-form-elements-with-same-name-prefix/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.