I want to show the value of a form on clicking of a checkbox and after selecting a checkbox I want that one of our input box of my form which is disabled show the name of checkbox in that field.I also want to get the id of that checkbox. I am working in laravel .
<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>
My Jquery Code....
$('.checkbox1').on('change',function(e){
e.preventDefault();
var a = this.name;
$('.item').attr('val',a);
$('.shopped').show();
});
Try this:
$('.checkbox1').on('change',function(e){
e.preventDefault();
var a = this.name;
$('.item').val(a);
$('.shopped').show();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.