Only one checkbox can be checked

prabhmeet
Giga Expert

Hi,

I am a newbie and not too good in scripting.

I am creating a Catalog item and there I have 2 check boxes, I want that only one can be selected at a time.

I know this can be done if I create radio buttons but I have been specifically asked to create checkboxes.

 

This is the onChange Client Script on function variable.

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

//Type appropriate comment here, and begin script below

if(newValue == true){
g_form.setValue('menu','false');
}

This is the onChange Client Script on menu variable.

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

//Type appropriate comment here, and begin script below

if(newValue == true){
g_form.setValue('function','false');
}

Can anyone help with the script?

1 ACCEPTED SOLUTION

Last try,

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

//Type appropriate comment here, and begin script below

if(newValue == true  || newValue == 'true'){

alert("inside if");
g_form.setValue('menu', false);
}
}

//this is onchange client script on menu variable

if(newValue == true  || newValue == 'true'){

alert("inside if");

g_form.setValue('fuction', false);

}

View solution in original post

12 REPLIES 12

rad2
Mega Sage

The variable type - multiple choice creates radio buttons. this can be used to select only one option at a time.

link - https://docs.servicenow.com/bundle/london-it-service-management/page/product/service-catalog-management/reference/r_VariableTypes.html#d198680e1058

Hi,

I do not want radio buttons. I have been specifically asked to create checkboxes.

In that case, you can use UI policies to restrict values into the other checkbox

ryan_pope
Mega Guru

I would agree with Rad that the multiple choice is the optimal way of getting to this point, but if, for whatever reason, checkboxes are required, you'd probably need to write a catalog client script onChange of each checkbox where if newValue=true, then set the value of all other checkboxes to false.