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

Question

Question

hide submit button based on current date minus 3 days in the date field

asked on August 19, 2021

Hi,

I've been searching for how to hide the "Submit" button on a form if the date is within 3 days of the current date and haven't found anything that works for my situation.  right now I have this:

$(document).ready(function() {
    var $submit = $('.Submit');
    $submit.hide();
    $("#Field6").on("change", function() {
        if ($(this).val() == " don't know what would go here..."){
            $submit.show();
        } else {
            $submit.hide();
        }
    });
});

(Field 6 is Appointment Date) 

What we're trying to say is, you can't cancel the appointment if it's within 72 hours (3 days) from the current date.

0 0

Replies

replied on August 19, 2021 Show version history

Hi Donnie,

.val() on Date field will get the date string. To compare with another date, either convert both of them to string or Date object.

Try following code

$(document).ready(function() {
    var $submit = $('.Submit');
    $submit.hide();
    
    var lastDay = new Date();
    lastDay.setDate(lastDay.getDate() - 3);
    lastDay.setHours(0, 0, 0, 0); //ignore time
  
    $("#Field6").on("change", function() {
        if (Date.parse($(this).val()) < lastDay){
            $submit.show();
        } else {
            $submit.hide();
        }
    });
});

 

0 0
replied on August 20, 2021

Ziyan,

thanks so much for the help!  I've been told I asked the question wrong originally.  I should have said: If someone wants to cancel their appointment within 72 hours (including today), allow the submit button. Otherwise, hide the submit button.  For example: if I have an appointment on 9/1/2021, the submit button will not show. The purpose of the form is only to allow cancellation within 72 hours.

I'm sorry if I am confusing you, as you can probably tell it's confusing to me also.

Any more help would be greatly appreciated!

0 0
replied on August 22, 2021

Overall the script should still work. Just need to change how to calculate the day by changing - 3 to + 3, I suppose?

0 0
replied on August 31, 2021

Ziyan,

Thanks so much for the help! After making changes to the .show & .hide and changing the -3 to +3 I was able to make it work like we needed it to. Thanks for giving me the basics to work with.

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

Sign in to reply to this post.