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

Question

Question

Disable submit button when duplicate SSN detected

asked on April 3, 2020

  I need another pair of eyes on this Forms code.

  The situation is that someone comes in as a new client, but they actually have a file from a few years ago.  I lookup SSN and the populate a hidden field with their name.  If the hidden field is not empty I show a read-only field with a default value of a duplicate client warning.  I want to disable the submit button in this circumstance.  The submit button is on the second tab.

  I am trying to evaluate the value of the hidden name field when the SSN field loses focus.  I'm sure I'm missing something in the finicky jQuery syntax.  I'm an experienced coder, but not experienced with JS and JQ.

$(document).ready(function () {
// Disable submit button if duplicate client warning is displayed
    $('#q7 input').blur(function () {
        if ($('#q73').val() !== '' {
            $('.Submit').attr("disabled", "disabled");
        } else {
            $('.Submit').removeAttr("disabled");
        }
    });
});

 

0 0

Answer

SELECTED ANSWER
replied on April 3, 2020
$(document).ready(function() {
    // optional: disable submit button on form load
    $('.Submit').attr("disabled", true);

    // Disable submit button if duplicate client warning is displayed
    $('#q7 input').change(function() {
        if ($('#q73').val() !== '') {
            $('.Submit').attr("disabled", true);
        } else {
            $('.Submit').attr("disabled", false);
        }
    });
});

I usually like to use the change event rather than blur but either one should work in your case. I just changed the removeAttr to set disabled to false in both cases, which I tested and works in my browser. Hopefully that does it!

And when making any kind of JavaScript changes I always copy and paste from Visual Studio Code. It has a lot of syntax checkers and intellisense functions that make it much more user friendly than doing it directly in LF Forms.

1 0

Replies

replied on April 3, 2020

Hey James, as far as syntax goes you're just missing a closing paren on line 4. Your code should work with just that paren added, but I also updated a few other spots (attr("disabled", true) and added your block to disable the submit button on page load)

$(document).ready(function () {
    // optional: disable submit button on form load
    $('.Submit').removeAttr("disabled");

    // Disable submit button if duplicate client warning is displayed
    $('#q7 input').blur(function () {
        if ($('#q73').val() !== '') {
            $('.Submit').attr("disabled", true);
        } else {
            $('.Submit').removeAttr("disabled");
        }
    });
});
3 0
replied on April 3, 2020 Show version history

Brian,  You've got me halfway there.  Thanks.  It would be nice to have an old fashioned syntax checker for JS & JQ.

The remaining issue is that the button is not re-enabled after the SSN is corrected.  Is blur the best event to be testing here?

0 0
SELECTED ANSWER
replied on April 3, 2020
$(document).ready(function() {
    // optional: disable submit button on form load
    $('.Submit').attr("disabled", true);

    // Disable submit button if duplicate client warning is displayed
    $('#q7 input').change(function() {
        if ($('#q73').val() !== '') {
            $('.Submit').attr("disabled", true);
        } else {
            $('.Submit').attr("disabled", false);
        }
    });
});

I usually like to use the change event rather than blur but either one should work in your case. I just changed the removeAttr to set disabled to false in both cases, which I tested and works in my browser. Hopefully that does it!

And when making any kind of JavaScript changes I always copy and paste from Visual Studio Code. It has a lot of syntax checkers and intellisense functions that make it much more user friendly than doing it directly in LF Forms.

1 0
replied on April 3, 2020 Show version history

Brian, Thanks a lot for your help.

It turns out that the trigger for q7 was being executed before the value of q73 was set by the lookup.  So I decided to stop making my life difficult and trigger off of the change to q73.  Voila.

Here is the final code

$(document).ready(function() {
  $('#q73 input').change(function() {
        if ($('#q73 input').val() == '') {
            $('.Submit').attr("disabled", false);
        } else {
            $('.Submit').attr("disabled", true);
        }
  });
});

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

Sign in to reply to this post.