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

Hi ,

I have two checkboxes 'Menu' and 'Function'

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');
}
}

 

Similarly for menu checkbox, but this is not working. 

Please try as below,

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

//Type appropriate comment here, and begin script below

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

Hi Shweta,

I tried this, even now its not working.

// this is 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 onchange client script on menu variable

if (newValue == true){

g_form.setValue('fuction', false);

}

 

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);

}

thanks a lot shweta, it is working now.