You are viewing limited content. For full access, please sign in.

Question

Question

Hide submit button based on radio button choice

asked on October 31, 2017

I would like to hide the submit button if the user answers "Yes" to any of the three questions asked.  How could I do this with java?

3 0

Answer

SELECTED ANSWER
replied on October 31, 2017 Show version history

First, add a class called "hideSubmit" to the advanced tab of the fields you want to use to trigger the change, then add the following JavaScript code to your form.

$(document).ready(function(){
  // apply event handler to radio inputs
  $('.hideSubmit input').change(function(){
    // if 1 or more YES selections are found
    if($('.hideSubmit input[value="YES"]:checked').length > 0){
      // hide submit button
      $('.Submit').hide();
    }
    // otherwise
    else{
      // show submit button
      $('.Submit').show();
    }
  });
});

What this does is assign a change event handler to any input element with the "hideSubmit" class. When the change event fires, it counts how many "YES" options are checked, if 1 or more are selected, it hides the submit button, if 0 are selected, it shows it again.

Just make sure you are matching to the value attribute of the options and not just the text that is displayed next to the button because they can differ depending on how you configured them.

4 0
replied on October 31, 2017

Thank you Jason! It worked perfectly! smiley

1 0
replied on January 22, 2018

Hi Jason,

 

   Sorry to jump on this thread. Can this code be adjusted to hide the submit button by default, and then only display it once a yes button is checked?

 

Thanks,

Michael

0 0
replied on January 22, 2018 Show version history

Absolutely, but in that case it would make more sense to call the CSS class "showSubmit" instead.

$(document).ready(function(){
  // hide submit by default
  $('.Submit').hide();

  // apply event handler to radio inputs
  $('.showSubmit input').change(function(){
    // if 1 or more YES selections are found
    if($('.showSubmit input[value="YES"]:checked').length > 0){
      // show submit button
      $('.Submit').show();
    }
    // otherwise
    else{
      // hide submit button
      $('.Submit').hide();
    }
  });
});
2 0
replied on January 22, 2018

Jason,

 

   Thank you very much, you rock!

 

Thanks,

Michael

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.