0

So I would like to know after form submitting if a checkbox is checked or not.

I used this lines:

var isChecked = $('#USR_RememberMe').attr('checked') ? true : false;
alert(isChecked);

But isChecked is equals to false each times.

Could you please help me ?

teamo
  • 443
  • 1
  • 7
  • 16
  • `$('#USR_RememberMe').checked` should also work. – Stuart Wagner Jul 14 '15 at 23:54
  • possible duplicate of [Testing if a checkbox is checked with jQuery](http://stackoverflow.com/questions/4813219/testing-if-a-checkbox-is-checked-with-jquery) – Dave Jul 14 '15 at 23:57
  • Try [`.prop()`](http://api.jquery.com/prop/) instead of [`.attr()`](http://api.jquery.com/attr/). Also, note the "*Attributes vs. Properties*" section in the documentation for `.prop()`. – Jonathan Lonowski Jul 14 '15 at 23:57

1 Answers1

3

Do this:

$("#USR_RememberMe").is(":checked");

:checked is a pseudo class.

potashin
  • 44,205
  • 11
  • 83
  • 107
Francisco Goldenstein
  • 13,299
  • 7
  • 58
  • 74