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

Question

Question

Hide or Show the Approve or Reject buttons based on a Checkbox selection

asked on June 11, 2019

I've applied the following javascript that I found in an older post to a checkbox variable and it works properly when you check/uncheck the box on a form in the process manually.  When you manually check the box, the Reject button disappears.  When you manually uncheck the box, the Approve button disappears and the Reject button appears.  

However it doesn't automatically execute when the page first loads.  On the page load, both buttons appear on the bottom of the screen even though the checkbox is not checked.  I would like the Approve button hidden when the page first loads as the variable is always unchecked to begin with on the first form it appears on, but currently both buttons are showing.  Any suggestions?

$(document).ready(function () {
  $("#q1").on("change", function() {
    if($('#Field1-0').is(':checked')) {
        $(".action-btn.Reject").hide();
        $(".action-btn.Approve").show();
    }
    else {
        $(".action-btn.Approve").hide();
        $(".action-btn.Reject").show();
     }
    });
});

 

0 0

Answer

SELECTED ANSWER
replied on June 11, 2019

Hello Levi,

 

It looks like you are only hiding/showing the buttons on a change event. If you hide the button on document ready this should solve this problem see below! Hope this helps :)

 

$(document).ready(function () {

  $(".action-btn.Approve").hide();

  $("#q1").on("change", function() {
    if($('#Field1-0').is(':checked')) {
        $(".action-btn.Reject").hide();
        $(".action-btn.Approve").show();
    }
    else {
        $(".action-btn.Approve").hide();
        $(".action-btn.Reject").show();
     }
    });
});

 

3 0

Replies

replied on June 11, 2019

Christian,

Thank you very much.  That knocked it out.

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.