I have a simple function that disables / enables the select element when the checkbox is checked or unchecked. It works well. However, after submitting the form and checking the flag, it has already been checked (using PHP) the selection is not disabled until I double-click on this flag.
<select id="worldSelect" class="select" name="world">
<input id="worldcb" type="checkbox" checked="yes" value="any" name="world">
any world
function toggleSelection(element){
if (this.checked) {
$(element.data).attr('disabled', 'disabled');
} else {
$(element.data).removeAttr('disabled');
}
}
$(function() {
$('#worldcb').click('#worldSelect', toggleSelection);
});
I tried a few things, however I'm not very good at jQuery yet ...
source
share