Testing if a checkbox is checked with jQuery

Rajeev

If the checkbox is checked, then I only need to get the value as 1; otherwise, I need to get it as 0. How do I do this using jQuery?

$("#ans").val() will always give me one right in this case:

<input type="checkbox" id="ans" value="1" />
Andy Mikula

Use .is(':checked') to determine whether or not it's checked, and then set your value accordingly.

More information here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related