Laravel:如何从复选框中获取值以及从文本输入中获取值
Laravel: How to get the value from the checkbox along with the value from the text input
我输入了 id
和 ballance
,id
作为复选框,ballance
作为文本输入。我希望在选中 id
时,ballance
请求与选中的 id
相匹配。但此时所有 ballance
进入请求。如何从前端&后端解决问题?
我的看法:
我的查看代码:
<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>
我的return请求:
我的后端:
public function store(Request $request)
{
return $request;
}
谢谢..
最简单的方法是拥有余额数组。所以你可以获得那些不为 0 的值并将它们推送到新数组然后你就可以开始了!
id 数组的第一个索引是新数组的第一个索引。您可以将它们存储在另一个数组或 db
当 html 中的 input
为 disabled
时,该值不会发送到控制器。
所以试试这个:
<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>
并且在页面加载时,您必须 Disable
所有 input type text
,未选中此 tr
的 checkbox
。
我输入了 id
和 ballance
,id
作为复选框,ballance
作为文本输入。我希望在选中 id
时,ballance
请求与选中的 id
相匹配。但此时所有 ballance
进入请求。如何从前端&后端解决问题?
我的看法:
我的查看代码:
<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>
我的return请求:
我的后端:
public function store(Request $request)
{
return $request;
}
谢谢..
最简单的方法是拥有余额数组。所以你可以获得那些不为 0 的值并将它们推送到新数组然后你就可以开始了! id 数组的第一个索引是新数组的第一个索引。您可以将它们存储在另一个数组或 db
当 html 中的 input
为 disabled
时,该值不会发送到控制器。
所以试试这个:
<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>
并且在页面加载时,您必须 Disable
所有 input type text
,未选中此 tr
的 checkbox
。