Show/Hide based on Checkbox selection

I created a form collecting the form user's name, address, city, state, zip, etc. Then I have a check box that I would like the form user to check if the billing information is the same as the user information. Once this checkbox is selected, the billing section will hide. I am a JavaScript novice and reviewed the current help information regarding dynamic forms and JavaScript but I am not having any luck. Maybe I am going about this in the wrong order. Either way, I would appreciate someone steering me in the right direction to get a solution to hide the billing information.

Thanks for your assistance.

Hello @gwmyers,

Welcome to Plumsail Community!

For this, you need to put all fields and controls inside Grid container.
image

And assign a CSS class to it, e.g. billing-info.
image

And you need to add this code in JavaScript editor. Please don't forget to replace Checkbox with the internal name of the field.

fd.spRendered(function() {

    function hideBilling() {

        if(fd.field('Checkbox').value.length == 0) {
            $('.billing-info').show();
        }
        else {
            $('.billing-info').hide();
        }
    }

    // Calling hideBilling when the user changes the field
    fd.field('Checkbox').$on('change', hideBilling);

    // Calling hideBilling on form loading
    hideBilling();
});

Thank you. I will give this a try. I think I was almost there but was missing the grid element.

1 Like

Well, I thought I had it and then tested but the billing information grid is still not hiding when the checkbox is selected. Here is my code and some screenshots. Also here is the link to the form. What in the world am I missing?

.

fd.spRendered(function() {

function hideBilling() {

    if(fd.field('cbxBillingInfo').value.length == 0) {
        $('.billing-info').show();
    }
    else {
        $('.billing-info').hide();
    }
}

// Calling hideBilling when the user changes the field
fd.field('cbxBillingInfo').$on('change', hideBilling);

// Calling hideBilling on form loading
hideBilling();

});

Hello @gwmyers,

I'm sorry, I thought you are using Forms for SharePoint.

For Public forms please use rendered() event in the code. Please see updated code below.

fd.rendered(function() {

function hideBilling() {

    if(fd.field('cbxBillingInfo').value.length == 0) {
        $('.billing-info').show();
    }
    else {
        $('.billing-info').hide();
    }
}

// Calling hideBilling when the user changes the field
fd.field('cbxBillingInfo').$on('change', hideBilling);

// Calling hideBilling on form loading
hideBilling();
});

Ah...thanks for educating me that there is a difference in the functions used for Public and SharePoint forms. Next time, I will make sure I communicate which Forms application I am using.

Thanks again for your assistance.

1 Like

Hi

I would like to open this topic again. I would like to make a single ComboBox "ReadOnly" or "Disabled" and I modified the code like this, but it doesn't work. Can someone help me?

fd.spRendered(function() {

    function hideParent() {
		if(fd.field('IsChilditem').value == true) 
		{
           fd.field('ParentItem').disabled = false;
        }
        else 
		{
           fd.field('ParentItem').disabled = true;
        }
    }

    // Calling hideBilling when the user changes the field
    fd.field('IsChilditem').$on('change', hideParent);

    // Calling hideBilling on form loading
    hideParent();
});

Thanks in advance

Hello @T_H,

What is the type of the IsChilditem field? Are you getting any errors in the browser console (F12)? Please share the screenshot.

Hallo

Thanks for helping by my Problem.
The Error Screenshoot:

This is the Screenshoot from the Form Editor.

And i have test both functions names. fd.spRendered and fd.rendered

@T_H,

You are using Forms Designer for classic UI, you don't need fd.rendered() event and you must use the different code to get field value and show/hide fields. Please find code sample in Forms Designer documentation.

Just for the future, questions regarding Forms Designer are better answered in the official Forms Designer forum here - Forms Designer Forum - Index page

Hi @mnikitina,

Thanks for the Answere. I'll see if I can find a solution to my problem in the forum.

1 Like