I have a sidebar with a form inside each menu. I want to submit a form whenever user click a menu inside the sidebar with different data from foreach. The sidebar menu also created inside foreach.
<li >
<a href="javascript:void(0)"><span >Choose Company</span></a>
<ul style="">
@foreach ($company as $cp)
@if ($cp->name != Session::get('selected_company'))
//Whenever user clicked this list item
<li ><a href="javascript:void(0)" id="company"><span
data-i18n="eCommerce">{{ $cp->name }}</span></a>
</li>
// I want to submit this form
<form action="{{ route('select_company') }}" method="POST">
@csrf
<input type="hidden" value="{{ $cp->name }}" name="selected_company">
</form>
@endif
@endforeach
</ul>
</li>
How to do it using JQuery? I've tried to search how to solve it and found this way:
<script>
$('#company').click(function() {
$(this).closest('form').submit();
});
</script>
But it still not working, when I click the sidebar menu nothing was happened. Any help would be very helpful for me, thanks
CodePudding user response:
If I was you I would do something like this;
<li >
<form action="{{ route('select_company') }}" method="POST">
@csrf
<input type="hidden" value="{{ $cp->name }}" name="selected_company">
<input type="submit" value="{{ $cp->name }}"/>
</form>
</li>
and then style your submit button as you like