I want to submit my form after a user clicked/touched the checkbox:
THE HTML
<input type="checkbox" name="chkSales" id="chkSales" class="custom" data-inline="true" data-mini="true"/><label for="chkSales">Sales</label>
<input type="checkbox" name="chkArrival" id="chkArrival" class="custom" data-inline="true" data-mini="true"/><label for="chkArrival">New Arrival</label>
The Js:
$("input[type='checkbox']").change(function() {
alert(e);
print(e);
});
From what I read here it should really work, but id doenst! where is my problem?
(it should be change, since mobile devices don't click, they use touch... http://jsfiddle.net/usTHG/2/
change() updates the textbox value with the checkbox status. I use . click() to confirm the action on uncheck. If the user selects cancel, the checkmark is restored but .
To check whether a Checkbox has been checked, in jQuery, you can simply select the element, get its underlying object, instead of the jQuery object ( [0] ) and use the built-in checked property: let isChecked = $('#takenBefore')[0]. checked console. log(isChecked);
$("input[type='checkbox']").change(function(e) {
^---- you missed e here
alert(e.type);
print(e);
});
Working example
Try this please:
you are missing e
in your function(e
)
code
$("input[type='checkbox']").change(function(e) {
alert(e);
print(e);
});
try:
$(document).ready(function() {
$("input[type='checkbox']").change(function(e) {
alert(e);
print(e);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With