Disable some drop-down controls when the user clicks the checkbox

I have a dropdown time that shows the hour in one selection, minutes in another and AM / PM in the third. I have a flag that says "All day"

I want this when the user checks "All Day", all the select dropdowns become inaccessible.

+3
source share
3 answers

The problem with the checkboxes is to make them work right in IE6, as the event changefires at all kinds of useless times.

Start with the function to disable:

function onCheckChange() {
  if ($("#all-day-checkbox").is(':checked'))
    $("select").attr('disabled', 'disabled');
  else
    $("select").removeAttr('disabled');
}

, select, , , select.some-class-to-identify-the-hours-and-minutes-and-seconds-dropdowns .

, , , : .

:

$("#all-day-checkbox").click(onCheckChange).change(onCheckChange);
$("label[for=all-day-checkbox]").click(onCheckChange);
+4
$('#allday').toggle(
    function(){
        $('#hour, #minutes, #am-pm').attr('disabled', 'disabled');
    },
    function(){
        $('#hour, #minutes, #am-pm').removeAttr('disabled');
    }
);
0

Try it.

$('#checkbox').change(function(){
    $('#Hour, #Minute, #Period').attr('disabled', this.checked);    
}); 
0
source

Source: https://habr.com/ru/post/1715672/


All Articles