I am trying to generate a list of forms using a foreach loop. The forms are just item names that use POST to pass their id to my controller so they can be updated. I am using onclick="form.submit()" to get the action.
This works as expected when there is only one item in list.
@foreach($items as $item)
{{ Form::open(['url'=>'item/view', 'name'=>'itemView']) }}
{{ Form::hidden('id', $item->id ) }}
<li><a href="#" onclick="itemView.submit()">{{ $item->name }}</a></li>
{{ Form::close() }}
@endforeach
However, as soon as the are >1 items I get a 'itemView.submt is not a function' error. I susoect this is because there are now duplicate form names.
QUESTION: How do I use the array index to make the form names unique?
I have tried this with no luck.
@foreach($items as $item)
{{ Form::open(['url'=>'item/view', 'name'=>'itemView[]']) }}
{{ Form::hidden('id', $item->id ) }}
<li><a href="#" onclick="itemView[].submit()">{{ $item->name }}</a></li>
{{ Form::close() }}
@endforeach
I am sure it's possible, not sure how.
Thanks!