Jump to content

Conditional logic for hidden elements

Recommended Posts

Hello!

I am trying to hide an element on a page that will become visible only when Other is selected by a previous option. So far I haven't had any luck trying to input the following code on a code block on the page:

<script>
    document.addEventListener('DOMContentLoaded', function() {
        // Add your logic here
        var previousOption = document.getElementById('select-2b0ae669-b004-4fdb-ade8-e90ac055f9b6-field');
        var hiddenField = document.getElementById('text-e7dabace-7e8e-4ad6-a440-6aab243810c0-field');

        // Initial state
        hiddenField.style.display = 'none';

        // Event listener for changes in the previous option
        previousOption.addEventListener('change', function() {
            if (previousOption.value === 'Other') {
                hiddenField.style.display = 'block';
            } else {
                hiddenField.style.display = 'none';
            }
        });
    });
</script>

 

I'm not even sure if this is doing what I think it's doing, so any help would be appreciated!

Link to comment
  • Replies 0
  • Views 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.