I print data in table and try to change name of specific hidden field
but i cant my code is as below
<table class="table table-hover">
<thead>
<tr>
<th>
<input type="checkbox">
</th>
<th>sr no</th>
<th>seller</th>
<th>shape</th>
<th>size</th>
<th>color</th>
<th>discount</th>
<th>client</th>
</tr>
</thead>
<tbody>
@foreach($cod_details as $cod)
<tr>
<td>
<input type="checkbox" name="ids[]" id="{{ $cod->id }}" value="{{ $cod->id }}">
<input type="hidden" value="{{ $cod->report_no }}" id="{{ $cod->report_no }}" name="" class="report">
</td>
<td>{{ $cod->id }}</td>
<td>{{ $cod->seller }}</td>
<td>{{ $cod->shape }}</td>
<td>{{ $cod->size }}</td>
<td>{{ $cod->color }}</t
<td>{{ $cod->discount }}</td>
<td>{{ $cod->client }}</td>
</tr>
@endforeach
</tbody>
</table>
this shows all details in table and working perfect.
$(document).ready(function(e){
$('input[type="checkbox"]').click(function(){
if($(this).prop("checked") == true){
$(this).closest('input[type="hidden"]').attr('name','report_no[]');
}
else{
}
});
});
I try to add name = report_no[]
on checked of checkbox but i cant.
It's the very next element in the DOM, immediately after the checkbox. So in your handler:
var input = $(this).next();
...will give you a jQuery wrapper for that input
field.
Side note: if($(this).prop("checked") == true){
is a very long-winded way to write if (this.checked)
, I'd just use that. :-)
So:
$('input[type="checkbox"]').click(function() {
if (this.checked) {
$(this).next().attr('name','report_no[]');
}
else {
}
});
If you want to clear it when the checkbox is unchecked, then:
$('input[type="checkbox"]').click(function() {
$(this).next().attr("name", this.checked ? "report_no[]" : "");
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments