Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a function by checking a checkbox JQuery

I am new at Jquery and was hoping for some advice as to how to call a jQuery function using a check box.

$(document).on("click", "input[name='chkBestSeller']", function () {

    alert("Thanks for checking me");

});

<input type='checkbox' name='chkBestSeller' value='Best Seller'/>

At the moment, it is not working.

like image 681
Arianule Avatar asked Nov 30 '22 12:11

Arianule


2 Answers

Try this:

<input type='checkbox' id='isSelected'/>

$('#isSelected').bind('change', function () {

   if ($(this).is(':checked'))
     alert("Checked");
   else
     alert("Unchecked");

});
like image 32
Deepak Ingole Avatar answered Dec 15 '22 10:12

Deepak Ingole


Try this:

$('input[name="chkBestSeller"]').click(function () {

    alert("Thanks for checking me");

});
like image 144
sangram parmar Avatar answered Dec 15 '22 09:12

sangram parmar