Laravel:如何从复选框中获取值以及从文本输入中获取值

时间:2020-11-02 08:29:21

标签: php laravel laravel-7

我输入了idballanceid作为复选框,ballance作为文本输入。我想在选中id时,ballance请求与选中的id相匹配。但目前所有ballance均已提出请求。如何从前端和后端解决问题?

我的观点:

view

我的查看代码:

<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>

我的要求退回:

enter image description here

我的后端:

public function store(Request $request)
{       
    return $request;
} 

谢谢..

2 个答案:

答案 0 :(得分:1)

最简单的方法是拥有余额阵列。因此,您可以获得那些不为0的值并将其推入新数组,然后就可以使用了! id数组的第一个索引用于新数组的第一个索引。您可以将它们存储在另一个数组或数据库中

答案 1 :(得分:1)

当html中的inputdisabled时,该值将不会发送给控制器。
所以试试这个:

<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,而checkbox中的tr未被选中。