Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkbox bind CHANGE event

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/

like image 548
ItsMeDom Avatar asked Jun 20 '12 06:06

ItsMeDom


People also ask

How can create checkbox click event in jQuery?

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 .

How do you check checkbox is checked or not?

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);


3 Answers

$("input[type='checkbox']").change(function(e) {
                                            ^---- you missed e here
    alert(e.type); 
    print(e);
});​

Working example

like image 137
thecodeparadox Avatar answered Oct 04 '22 13:10

thecodeparadox


Try this please:

you are missing e in your function(e)

code

$("input[type='checkbox']").change(function(e) {
    alert(e);
    print(e);
});​
like image 20
Tats_innit Avatar answered Oct 04 '22 11:10

Tats_innit


try:

$(document).ready(function() {
        $("input[type='checkbox']").change(function(e) {
            alert(e);
            print(e);
        });
    });
like image 22
Mantas Vaitkūnas Avatar answered Oct 04 '22 11:10

Mantas Vaitkūnas