Hide/show Java Script not effecting created form

Hi there,
I'm new to Plumsail and need to create a form in which texts pop up, if a toggle is used.
I tried the JavaScript multiple times but no matter what kind of code I add in the JavaScript editor, my form doesn't change.
How do I get my forms to execute the code I implemented?

I used the following code from the documentation:

fd.spRendered(function() {

    function hideOrShowField() {
        if (fd.field('Nachlass').value) {
            // Show the MyField field
            fd.field('Preisnachlassunterlagen').hidden = false;
        } else {
            // Hide the MyField  field
            fd.field('Preisnachlassunterlagen').hidden = true;
        }
    }

    // Calling hideOrShowField when the YesNo value changes
    fd.field('Nachlass').$on('change',hideOrShowField);

    // Calling hideOrShowFieldon form loading
    hideOrShowField();

});

Thank you so much!
Jana

Dear Jana,
The code looks correct. Are you using SharePoint forms or Public Web Forms? For public web forms you only need to change fd.spRendered to fd.rendered and it should work.

If you're using SharePoint forms and it's not working, please, check browser's console for errors and post a screenshot here, we'll see what exactly fails.

Also, make sure is not commented out - if it's all green/blue, it's commented out, it should be in color:
image

Thank you so much, I could solve all my problems using your line!

Hello, I am experiencing the same issue sorta. FYI, I am not a coder. I've tried all the scripts that I've found relating to this around this site and nothing has worked. I am using public forms.
When the user selects 'Yes' from a dropdown (Yes/No option) the attachment field is made required or they get an error and cannot proceed. I tried the code below, but it didn't work.

image

I then tried to just show/hide and that didn't work either.

image

What am I doing wrong?
Thank you in advance for your assistance.

Dear @Ameerah33,
If the value is in dropdown choice, you should check not length of value nor if the field has value, but for specific value, like so:

if(fd.field('FitTestCompleted').value == 'Yes'){

You also seem to confuse fd.field and fd.control - use the correct version, for Attachments field, it should be:

fd.field('MaskFitUpload')

If the code still doesn't work, please, send us the code as text, so we can help adjust it - it's not possible from a screenshot.

Thanks @Nikita_Kurguzov. I've made the corrections as you stated. It's still not working for me, though. The form loads up, and the attachment field (MaskFitUpload) is not hidden.

fd.Rendered(function() {
	
		function hideOrShowAttachment() {
			if (fd.field('FitTestCompleted').value == 'Yes') {
			
			// Show Attachment field
			fd.field('MaskFitUpload').hidden = false;
		} else 
		{
			// Hide Attachment field
			fd.field('MaskFitUpload').hidden = true;
		}
	}
	
	// Calling hideOrShowAttachment when field value=Yes
	fd.field('FitTestCompleted').$on('change', hideOrShowAttachment);
	
	// Calling hideOrShowAttachment on form loading
	hideOrShowAttachment();
	
    
});

Thanks again!

Dear @Ameerah33,
One more thing I've just noticed is fd.Rendered - it should be:

fd.rendered(function(){

Capitalization is important in JavaScript.

If it still doesn't work - please, export the form and send it to us at support@plumsail.com to analyze for you.

Thank you. I made the corrections and it worked, once, then it didn't. I'll do as you suggested and send it over to support.

Thanks!