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

Question

Question

Submit Button Hidden in Draft

asked on November 29, 2021

Hello, 

I have a form where I want the submit button to show only if a variable =1. This works unless a user opens a form that was saved as a draft. When a draft is open, the submit button does not appear unless there is a change to the variable on the form. Is there anything I can add to my script so the submit button will always appear when the variable =1? Thanks! 

 

$(document).ready(function() {
    var $submit = $('.Submit');
    $submit.hide();
    $('#q156 input').on("change", function() {
        if ($('#q156 input').val() == "1"){
            $submit.show();
        } else {
            $submit.hide();
        }
    });
});

0 0

Answer

SELECTED ANSWER
replied on November 30, 2021

It could look like this, where the Hide is in a function that is called when the Form is loaded and then again if the input value is changed on the field

 

$(document).ready(function () {
  
HideSubmit();
  
$('#q156 input').change(HideSubmit);
  
    function HideSubmit() {
          if ($('#q156 input').val() == "1") {
          $('.Submit').show();
        }
          else { 
             $('.Submit').hide();
        }
    };
});

1 0
replied on November 30, 2021

You can also simplify the if/else by using .toggle(true/false) instead of separate show and hide calls, but I know sometimes people prefer to keep the if/else for readability.

$('.Submit').toggle($('#q156 input').val() == "1");

0 0
replied on December 2, 2021

Thank you!

0 0
replied on December 2, 2021

Thank you! 

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.