user3095976
user3095976

Reputation: 135

JQuery check status of checkbox

I am using the following code to check the status of a check box - I get back a 'Y' when enabled but returns undefined when it is disabled. How can ensure my JS does not throw and error and can detect the appropriate states at run time - ideally would like to have a Y or N answer to the selector.

Thanks

  var isRequested = $('input[name=componentId]:checked').val();

Upvotes: 0

Views: 118

Answers (2)

Anton
Anton

Reputation: 32581

You can use .is(':checked')

var isRequested = $('input[name=componentId]').is(':checked');//True||False

Upvotes: 1

Murali Murugesan
Murali Murugesan

Reputation: 22619

Try using prop()

 var isRequested =$('input[name=componentId]').prop('checked')

Upvotes: 1

Related Questions