Reputation: 139
I have input id
and ballance
, id
as check box and ballance
as text input. I want when the id
is checked, the ballance
request matches the id
that was checked. but at this time all ballance
entered into request. How to solve the problem from front-end & back-end?
My view:
My view code:
<th>
<div>
<input name="id[]" value="{{$item->id}}" type="checkbox"> <label class="" for="{{$item->id}}"></label>
</div>
</th>
<td> {{ $item->id }} </td>
<td>
<input type="text" class="form-control form-control-sm txtInt saldoChild" name="ballance[]" size="1" id="{{$item->id}}" value="0">
</td>
My return of request:
My backend:
public function store(Request $request)
{
return $request;
}
Thanks..
Upvotes: 0
Views: 376
Reputation: 797
when an input
in html is disabled
, the value of that wont send to controller.
so try this:
<script>
$('input[type="checkbox"]').on("change", function(){
if($(this).is(":checked")){
$(this).closest('tr').find('.saldoChild').prop("disabled",false); //Enable the textBox
}
else{
$(this).closest('tr').find('.saldoChild').prop("disabled",true); //Disable the textbox
}
});
</script>
and at the page loading you have to Disable
All input type text
, that the checkbox
of this tr
is unchecked.
Upvotes: 1
Reputation: 636
easiest way is that you have your balance array. so you can get those value who are not 0 and push them to new array and then you are good to go! first index of id array is for first index of your new array. you can store them in another array or in db
Upvotes: 1