JavaScriptjQuery

Get checkbox value in jQuery

To get the checkbox value in jquery you have written some scripts like below.

$("input[type='checkbox']").val();

Or if you have set a class or id for it, you can:

$('#check_id').val();
$('.check_class').val();

However this will return the same value whether it is checked or not, this can be confusing as it is different from the submitted form behavior.

To check whether it is checked or not, do:

if ($('#check_id').is(":checked"))
{
  // it is checked
}

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button