Disable Enable Button for specific Date in jQuery

Last Reply one month ago By pandeyism

Posted one month ago

I want to disable the button for Specific dates only in jquery

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>DOM Example</title>
        <script src="jquery-3.1.1.min.js"></script>
        <script>
            var thisDay = new Date().getDate();  
            function checkButton()
            {
                if (thisDay>=15 && thisDay<=16)) 
                {
                    $("#add").prop("disabled", true);
                }
                printAlert();
            }

            function printAlert() {
                window.alert('We are not accepting entries right now.');
            }
        </script>
    </head>
    <body>
        <p id="firstParagraph">This is the first paragraph</p>
        <button id="add">Button</button>        
    </body>
</html>

 

Posted one month ago

Hi sathya2496,

Refer below sample.

HTML

<div>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var thisDay = new Date().getDate();
            if (thisDay >= 15 && thisDay <= 25) {
                $("#add").attr("disabled", true);
                printAlert();
            } else {
                $("#add").attr("disabled", false);
            }
        });
        function printAlert() {
            window.alert('We are not accepting entries right now.');
        }
    </script>
    <button id="add">Button</button>
</div>

Demo