How to Make the select box ReadOnly based on the values of Checkbox (Scoped Application)

Pravalika1
Tera Contributor

Hi Experts,

 

we have requirement to set the default value to a select box and make it readonly when the check is unchecked.

and when the check box is checked then the we need to diplay the list of choices to allow the user to select.

 

I have create and onload script is working as exopected, and I also need to implement the same for onChange of checkbox...which is not working.

 

 

function onLoad() {
var caIndicator = g_form.getValue('cloud_application_indicator');
if (caIndicator == 'true') {
g_form.addOption('module_code', 'OTH', 'OTH');
g_form.addOption('module_code', 'BAK', 'BAK');
g_form.addOption('module_code', 'JOB', 'JOB');
g_form.addOption('module_code', 'WEB', 'WEB');
} else {
g_form.clearOptions('module_code');
g_form.setValue('module_code', 'OTH');
g_form.setReadOnly('module_code','true');

}

}

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue == 'false') {

g_form.clearOptions('module_code');
g_form.setValue('module_code', 'OTH');
g_form.setReadOnly('module_code', 'true');

} else if (newValue == 'true') {
g_form.setReadOnly('module_code', 'false');
g_form.clearOptions('module_code');
g_form.addOption('module_code', 'OTH', 'OTH');
g_form.addOption('module_code', 'BAK', 'BAK');
g_form.addOption('module_code', 'JOB', 'JOB');
g_form.addOption('module_code', 'WEB', 'WEB');
}

//Type appropriate comment here, and begin script below

}

 

 

Regards,

Pravalika

1 REPLY 1

Mohith Devatte
Tera Sage
Tera Sage

Hello @Pravalika1 ,

can you try this while comparing the newValue

if (newValue == 'false' || newValue == false) 

{

alert('inside if');

}

else if (newValue == 'true' || newValue==true) {
alert('inside else');
}

Check if the alerts are coming 

Hope this helps 

Mark my answer correct if this helps you 

Thanks