Javascript 在单击时显示窗体,并使用输入框的值显示窗体

Javascript 在单击时显示窗体,并使用输入框的值显示窗体,javascript,jquery,laravel,Javascript,Jquery,Laravel,我想在点击复选框时显示表单的值,在选中复选框后,我希望我的表单的一个被禁用的输入框在该字段中显示复选框的名称。我还想获取该复选框的id。 我在拉维尔工作 <table class="table table-bordered" style="width: 80%;margin:5% 10%;background:slateblue"> <tr> <th>#</th> <th>

我想在点击复选框时显示表单的值,在选中复选框后,我希望我的表单的一个被禁用的输入框在该字段中显示复选框的名称。我还想获取该复选框的id。 我在拉维尔工作

 <table class="table table-bordered" style="width: 80%;margin:5% 10%;background:slateblue">
        <tr>
            <th>#</th>
            <th>item</th>
            <th>item name</th>
            <th>Added_at</th>

        <tr>
        <?php $i=1 ?>
        @foreach($items as $item)
         <tr>
             <td><input type="checkbox" id="bought" name="{{$item->item_name}}" class="checkbox1"></td>
             <td>{{$item->id}}</td>
             <td>{{$item->item_name}}</td>
             <td>{{$item->date}}
            </tr>
        @endforeach
    </table>


<form class="shopped" method="post" action="{{url('post-data')}}" hidden><br>
    {!! csrf_field()!!}

    <h4 align="center">Add some information to mark as shopped</h4>
    <label for ="item">Items</label>
    <input type="text" class ="item"  disabled><br>
    <label for ="price">Price</label>
    <input type="text" name="price"><br>
    <label for ="store_name">Store</label>
    <input type="text" name="store_name"><br>
    <input type="submit" value="Add as purchased" class="btn btn-info" style="margin:20px 0 20px 60px"><br>
</form>
试试这个:

$('.checkbox1').on('change',function(e){
    e.preventDefault();
    var a = this.name;
    $('.item').val(a);
    $('.shopped').show();
 });

这不管用吗?为什么?您遇到了什么错误?它显示表单,但在禁用的输入字段中没有值。您的jQuery代码是否正常工作?或者至少已初始化?是,这正在工作,但未将值添加到禁用字段。
$('.checkbox1').on('change',function(e){
    e.preventDefault();
    var a = this.name;
    $('.item').val(a);
    $('.shopped').show();
 });