I have a simple code that just has to check if a checkbox is checked and if so enable some fields that, by default, should be disabled.
I have written the next code which I know can be severely improved. Could anyone tell me how? I tried getting the siblings of the checkbox also but that just caused some troubles.
$(function(){
$('#amount').attr('disabled','disabled');
$('#period').attr('disabled','disabled');
$('#key').attr('disabled','disabled');
$('#api').change(function(){
if($('#apiEnabled').is(':checked')){
$('#amount').attr('disabled','');
$('#period').attr('disabled','');
$('#key').attr('disabled','');
}else{
$('#amount').attr('disabled','disabled');
$('#period').attr('disabled','disabled');
$('#key').attr('disabled','disabled');
}
});
});