Reputation: 135
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
Reputation: 32581
You can use .is(':checked')
var isRequested = $('input[name=componentId]').is(':checked');//True||False
Upvotes: 1
Reputation: 22619
Try using prop()
var isRequested =$('input[name=componentId]').prop('checked')
Upvotes: 1