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

Can you mark my answer as correct/helpful and close the thread.

ryan_pope
Mega Guru

Prabhmeet is right! When coding for checkboxes in a catalog item, a checkbox variable takes a javascript boolean (so true or false, without quotations).

 

It looks like you've spelt "function" wrong in your latest post of the code for the menu script. Probably should be:

g_form.setValue('function', false); instead of 'fuction'.

Jordan Vignoni
Tera Guru

You could use two onChange scripts - one for "Menu" and the other for "Function".  Below is an example of the script you can use in the "Menu" onChange script that will make "Function" read-only:


if (newValue == 'true') {
     g_form.setDisabled('function', true);

//This allows the end-user to change their selection on the form (if applicable).
} else if (newValue == 'false') {
     g_form.setDisabled('function', false);

}

This same script can be applied to the onChange script for "Function", but it would use 'menu' (instead of 'function').