Jump to content

Code Injection to Hide/Show form fields on radio button selection

Recommended Posts

Posted (edited)

Hoping someone can help. My form starts with a question with radio button yes/no options. I have the rest of the form hidden. I want the other fields to show based on "yes" selected, and an alternate message to show based on "no". Hiding the fields works just fine, but cannot get it to show the other fields or alternate message when an option is selected. Simply does not respond.

Update; Not sure if it matters, but I have two forms on my site.

HEADER

<style>
      #name-yui_3_17_2_1_1691440449790_2736,
      #text-c8e03340-5c6a-4381-98c6-f3711a8d4c3f,
      #email-yui_3_17_2_1_1691440449790_3674,
      #address-d08388fb-aa85-4d7d-9a8b-341e2ab6b52a,
      #phone-852a5090-b7af-468e-8b89-7659ed47501e,
      #date-5229ffa7-c73c-4650-a23a-eba73536f5dc,
      #select-cd4ecf1b-91b4-4e0f-b3a2-5493bf508f21,
      #checkbox-c79ed9e5-24e4-49d3-9a4e-7a0af1b06029,
      #textarea-yui_3_17_2_1_1691440449790_3676 {
   
      display: none;
      
      }  
</style>

 FOOTER

<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
        crossorigin="anonymous"></script>
<script>
  $('#radio-0cf8019f-6a21-49fa-ad77-b90df4cf9ab3 input').click(function(){
    selection = $(this).val();
    
    if (selection == 'Yes') {
          $('.form-item').show();
    }
    else
          if (selection == 'No') {
         $('').html('Thank You!!');
        }
  });
</script>

 

Edited by 2024_SyncOps
  • Replies 0
  • Views 1.2k
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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.