Reputation: 9909
I am using this code to disable a dropdown when user clicks on a checkbox
function onCheckChange() {
if ($("#all_day_checkbox").is(':checked'))
$("#evt_time_drop").attr('disabled', 'disabled');
else
$("#evt_time_drop").removeAttr('disabled');
}
$("#all_day_checkbox").click(onCheckChange).change(onCheckChange);
This works fine. But I would like to add an instruction to inject a true
or false
value to the checkbox so this can be stored in the database.
Unfortunately this doesn't work:
function onCheckChange() {
if ($("#all_day_checkbox").is(':checked'))
$("#evt_time_drop").attr('disabled', 'disabled');
$("#all_day_checkbox").val("TRUE");
else
$("#evt_time_drop").removeAttr('disabled');
$("#all_day_checkbox").val("FALSE");
}
$("#all_day_checkbox").click(onCheckChange).change(onCheckChange);
Anyone have suggestions to get to work?
Thanks for your help!
Upvotes: 1
Views: 5520
Reputation: 1
function onCheckChange() {
if ($("#all_day_checkbox").is(':checked')){
$("#evt_time_drop").attr('disabled', 'disabled');
$("#all_day_checkbox").val("TRUE");
}
else
{
$("#evt_time_drop").removeAttr('disabled');
$("#all_day_checkbox").val("FALSE");
}
}
Upvotes: 0
Reputation: 87073
Try this snippet:
$("#all_day_checkbox").val("FALSE");//For initially make the `checkbox` value FALSE
function onCheckChange() {
if ($("#all_day_checkbox").is(':checked')) {
$("#evt_time_drop").attr('disabled', 'disabled');
$("#all_day_checkbox").val("TRUE");
} else {
$("#evt_time_drop").removeAttr('disabled');
}
}
$("#all_day_checkbox").click(onCheckChange).change(onCheckChange);
Upvotes: 2
Reputation: 8942
What about
$("#all_day_checkbox").attr("checked", "") //for removing the check
$("#all_day_checkbox").attr("checked","checked") //for checking the box
And then just checking to see if the "checked" value equals "checked"...
Upvotes: 2