Checkbox Problem in Catalog Client Script

jeansky
Tera Contributor

Hello, I would like to ask why the select boxes don't show when I select the checkboxes. I don't know if this is possible in catalog client script. Any suggestion is appreciated. Thank you.

 

Here's my script:

 

function onChange(control, oldValue, newValue, isLoading) {

    g_form.setDisplay('checkbox1', false);
    g_form.setDisplay('checkbox2', false);
    g_form.setDisplay('checkbox3', false);
    g_form.setDisplay('selectbox1', false);
    g_form.setDisplay('selectbox2', false);
    g_form.setDisplay('selectbox3', false);

    var request_type = g_form.getValue('request_type');
    if (request_type == 'Account Creation') {
            g_form.setDisplay('checkbox1', true);
            g_form.setDisplay('checkbox2', true);
            g_form.setDisplay('checkbox3', true);

            var checkbox1 = g_form.getValue('checkbox1');
            var checkbox2 = g_form.getValue('checkbox2');
            var checkbox3 = g_form.getValue('checkbox2');

            if (checkbox1 == true) {
                g_form.setDisplay('selectbox1', true);
            }
            else if (checkbox2 == true) {
                g_form.setDisplay('selectbox2', true);
            }
            else if (checkbox3 == true) {
                g_form.setDisplay('selectbox3', true);
            }
            else {
                g_form.setDisplay('selectbox1', false);
                g_form.setDisplay('selectbox2', false);
                g_form.setDisplay('selectbox3', false);
            }
    }

    else if (request_type == 'Delete Account') {
            g_form.setDisplay('checkbox1', true);
            g_form.setDisplay('checkbox2', true);
            g_form.setDisplay('checkbox3', true);
    }
 
}

jeansky_1-1701355735680.png

 

jeansky_0-1701355687208.png

1 ACCEPTED SOLUTION

Based on my understanding of your code, I would suggest that within your new onChange client scripts on each Checkbox, you can have a condition like -

 

if(g_form.getValue('checkbox1')==true && g_form.getValue('request_type')=='Account Creation')

{

//show the select-box part

}

 

This way whenever RequestType if 'Delete Account' & even if CheckBox1 is true, you won't be showing SelectBoxes. Same logic you can put in all the other onChange client scripts as well.

 

Do mark this response as CORRECT / HELPFUL if you find it appropriate.

 

 

View solution in original post

8 REPLIES 8

Elijah Aromola
Mega Sage

This script only runs when the request_type value changes. If you need additional functionality to run when the check boxes are selected then you need to create onChange client scripts for each of those specific checkbox variables.

Hi Elijah, 

Thank you for your reply. 


If I will add an onChange client script on each Checkboxes1,2,3. It will also affect the request_type = "Delete Account". It will display also the selectbox1,2,3. Do I need to create new variables for Delete Account? I want to reuse the variables for checkboxes. What do you suggest?  Thanks.

No it should be fine. You want to separate out the scripts so that it makes sense. onChange of request type, we hide/show fields appropriately. onChange of checkbox1, checkbox2, etc. we have a separate script that hides/shows/updates what it needs to.

Based on my understanding of your code, I would suggest that within your new onChange client scripts on each Checkbox, you can have a condition like -

 

if(g_form.getValue('checkbox1')==true && g_form.getValue('request_type')=='Account Creation')

{

//show the select-box part

}

 

This way whenever RequestType if 'Delete Account' & even if CheckBox1 is true, you won't be showing SelectBoxes. Same logic you can put in all the other onChange client scripts as well.

 

Do mark this response as CORRECT / HELPFUL if you find it appropriate.