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

Question

Question

JavaScript Help: deactivate submit button

asked on August 9, 2018

From viewing other posts, I have achieved most of what I want with the script below.  It will hide the Reject button until someone clicks Yes on a radio button.  However, it does not disable the Approve button, or hide it.  Either option would be acceptable.  

Could anyone view my script and add the piece that would either disable or remove the Approve button if the targeted radio button has been clicked to Yes?

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

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

0 0

Answer

SELECTED ANSWER
replied on August 9, 2018

Thanks, Jason.  I tried a few things after your post, but couldn't make it do what I wanted.

Then I tried something else and it worked!

I found a post that had something slightly different and modified it.  The post was:  https://answers.laserfiche.com/questions/88465/How-do-I-disable-the-submit-button-when-the-page-loads#88530 and my new script is:

$(document).ready(function(){
  // apply event handler to radio inputs
  $('#q93 input').change(function(){
    // if 1 or more YES selections are found
    if($('#q93 input[value="Yes"]:checked').length > 0){
      // disable Approve button
           $('.Approve').prop('disabled',true);
        } else {
           $('.Approve').prop('disabled',false);
        }
  }).find('input.Approve').prop('disabled',false);
  
});

0 0
replied on August 9, 2018 Show version history

To clarify:  My new script does not hide any buttons, but when the radio button is switched to Yes, the Approve button is disabled.  And if I switch the radio button back to No, the Approve button becomes activated again immediately.

This works for my purposes!

0 0

Replies

replied on August 9, 2018

I would say to just right-click and inspect the button to get the correct class. Usually $('.Submit').hide() works for me since the default button class is Submit even if you change the text to say Approve.

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

Sign in to reply to this post.