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

Question

Question

Code not working in draft

asked on December 15, 2023

I have a form where I have the submit button showing if a field is "0.00". It is working great when just entering information and submitting it as usual, but it is not working when the user saves a draft. I think I have it narrowed down to the code.

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

The problem is that the user is entering all the information that causes the above code to work before saving the formas a draft.  When he opens the draft, there is no change to the field that is in the code, so the submit button does not show. 

Is there a way I can edit my code to run if there isn't a change, but the field is at zero? I tried blur, but it didn't seem to work. That being said, I am not a skilled coder and I may have just written it incorrectly.

 

0 0

Replies

replied on December 15, 2023 Show version history

Two options:

  1. Trigger the change event at the end of the $(document).ready code to force it to run
    • You can do this with $("#Field36").change()
  2. Move the applicable code out to a standalone function. Call that function inside the change event handler function, and also call the function somewhere inside $(document).ready

 

Basically, your current code responds to a change event, so you either need to manually trigger a change event or add a way to run it separately.

In both instances, you'll need to trigger the code when the form loads.

 

On a separate note, since you're already using jQuery, you could also simplify the show/hide code using the .toggle() method

// this (true = show, false = hide)
$submit.toggle($(this).val() == "0.00");

// will do the same thing as this
if ($(this).val() == "0.00"){
     $submit.show();
} else {
     $submit.hide();
}

 

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

Sign in to reply to this post.