0

I am trying to get the value of a checkbox and I tried the following:

var closedIssue = $('#closed-' + rowCounter).val();

but it always return 'on'

Here is the checkbox

<input type="checkbox" name="closed-' + rowCounter + '" id="closed-' + rowCounter + '" />

What am I doing wrong?

user979331
  • 11,039
  • 73
  • 223
  • 418

2 Answers2

2
var returnCheck = $('#closed-' + rowCounter).is(':checked');

will return you current status of checkbox.

ameenulla0007
  • 2,663
  • 1
  • 12
  • 15
0

Get the checked property using the .prop() method instead. It will return a boolean.

var closedIssue = $('#closed-' + rowCounter).prop('checked');

Or plain JavaScript:

var closedIssue = document.getElementById('closed-' + rowCounter).checked;
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304