How to know value is checked or no With Javascript and Sended to Laravel Controller
I have the modal with checkbox value and my problem is “how do i know the value has been checked on checkbox” and then how to send the checkbox values to laravel controller. I want a condition where the value contains 1 (active) when checked and 0 (not active) when not
How to know value is checked or no in javascript and Sended to Laravel Controller ?
to solve this problem, it's actually very easy, you only need to save the value at the time of submit to be like this
On my Modal Bootsrap i have input type checkbox with code like this
<div class="col-6" style="margin-top: 10px;">
<label class="form-label">Active</label>
<div class="checkbox-container">
<div class="checkbox">
<input type="checkbox" value="on" name="active" class="active checkbox-input"
id="update-form-active-checkbox" />
<label for="update-form-active-checkbox"></label>
</div>
</div>
</div>
On Javascript
$('#update-form').submit(function(event) {
const active = $(this).find('input[name=active]:checked').val();
On your Controller
$var_collected['active'] = $request->active == 'on' ? 1 : 0;
The example javascript code above will return 1 when the value is checked and 0 when the value is not checked or it means that if it is not checked the value is ON will produce an empty string
0 Response to "How to know value is checked or no With Javascript and Sended to Laravel Controller"
Post a Comment
Komentar yang Anda kirim akan terlebih dahulu di moderasi oleh Admin