Mohammad Nadeem
Mohammad Nadeem

Reputation: 9392

Read Checkbox checked property from HTML

I have an aspx page which renders as below.

<div id="div1">
<tr>
<td>SomeTxt</td>
<td><input checked="checked" class="check-box" disabled="disabled" type="checkbox" /></td>
<td>text2</td>
</tr>
</div>

Iam trying to read checkbox checked property from javascript :

var status = $('#div1 tbody tr:eq(' + tr.rowIndex + ') td:eq(1)').checked;

But I am getting undefined.

Upvotes: 0

Views: 240

Answers (5)

Devang Rathod
Devang Rathod

Reputation: 6736

Something like this

var status = $("input[type='checkbox']:checked").val();
alert(status);

Upvotes: 0

Anton
Anton

Reputation: 32591

use is(':checked')

var status = $('#div1 input[type="checkbox"]').is(':checked');

Upvotes: 3

Sridhar Narasimhan
Sridhar Narasimhan

Reputation: 2653

td:eq(1) will return td and not the input element

var status = $('#div1 tbody tr:eq(' + tr.rowIndex + ') td:eq(1)').find("input").get(0).checked;

Regards,

Upvotes: 0

ksugiarto
ksugiarto

Reputation: 951

you can use:

$("#yourID").is(":checked")

Make sure give an ID to your checkbox, not taking it <tr>

Upvotes: 0

Lee Kowalkowski
Lee Kowalkowski

Reputation: 11751

A TD will not have the checked attribute, you must select the input element.

Upvotes: 0

Related Questions