Reputation: 5382
What I'm trying to accomplish is:
When a user clicks the first Open until Filled option, leave the date input disabled. But when the user clicks on the second Open Until radio button. Have the date input enabled.
As of right now I can't seem to get it working. It seems to skip my check altogether. Am I missing something?
$(function() {
if ($('input#id_open:checked').length > 0) {
alert("please fill in the date");
$('input[name=end_date]').attr('disabled', false);
}
});
I made a fiddle here to show what I mean.
Thanks for your help in advance!
Upvotes: 0
Views: 288
Reputation: 11138
Working example: http://jsfiddle.net/8KggV/5/
$(function() {
$('input').click(function(){
if ($('#id_open:checked').length > 0) {
$('input[name=end_date]').attr('disabled', false);
}
else{
$('input[name=end_date]').attr('disabled', true);
}
})
});
Upvotes: 2
Reputation: 845
when using jQuery, to detect if a control is checked I use the is method. As well you don't need to check the length, as the is method return a boolean.
$(function() {
if ($('input#id_open').is(':checked')) {
alert("please fill in the date");
$('input[name=end_date]').attr('disabled', false);
}
});
Upvotes: 1