1

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!

3 Answers 3

2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

thanks @abdullah - this works nicely - still need to put $("#all_day_checkbox").val("FALSE"); inside the else or this will work only for one click on the checkbox
2

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"...

1 Comment

thanks @thomas - where should I insert your lines? i tried substituting lines 4 and 7 of my second code block in OP but didn't work
0
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"); 
} 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.