2

I have a series of div classes that populate with buttons. I need to disable the buttons only after a certain time of the CURRENT day passes to avoid the user clicking on them.

I was able to get this sort of working using this solution but it does not address only doing this for the CURRENT day and did not disable only the button from being clicked.

I really have no idea where to begin?

Here is my div. For example if it's past 1400 I want to disable zillow-4 div and if its past 1600 I want to disable zillow-5 :

<div id="zillow-4" style="height:50px;"><a class="button  " href="updateScheduleRequest.php?slotid=4&amp;timeremain=110&amp;current_date=2015-11-02&amp;empnum=702">Assign Slot 4</a></div>

<div id="zillow-5" style="height:50px;"><a class="button  " href="updateScheduleRequest.php?slotid=5&amp;timeremain=110&amp;current_date=2015-11-02&amp;empnum=702">Assign Slot 5</a></div>
Community
  • 1
  • 1
Rocco The Taco
  • 3,695
  • 13
  • 46
  • 79

3 Answers3

2

I think this does what you want?

<script type="text/javascript" >
    $(function(){
        disableChildButtonByTime(14, 0, "zillow-5");    
        disableChildButtonByTime(16, 0, "zillow-4");    

        function disableChildButtonByTime(hour, minute, parentId){
            var date = new Date();
            if(date.getHours() >= hour && date.getMinutes() >= minute){
                $("#" + parentId).children(".button").addClass("disabled");
            }
        }
    });
</script>

example: https://jsfiddle.net/eLegckag/1/

auto update version (this check the time once a minute):

https://jsfiddle.net/eLegckag/2/

Dhunt
  • 1,584
  • 9
  • 22
  • This looks great but I'm getting a syntax error in the function disableChildButtonByTime()? @dhunt ...no other messages though...any ideas? – Rocco The Taco Nov 02 '15 at 15:12
  • what browser are you using? I don't see any errors, using Chrome. Also, made an edit so that the data variable isn't global any more. – Dhunt Nov 02 '15 at 15:14
  • In Chrome it throws a 500 Server Error, in Dreamweaver I get a Syntax error on the function line @dhunt – Rocco The Taco Nov 02 '15 at 15:25
  • 500 error is internal server error so isn't related to this as its purely client side. That will be related to PHP. This is javascript, do you have it in PHP? Using time from PHP will use the servers time not the clients so may appear to be on the wrong day sometimes. I would use client side to make sure it appears correctly to the user. – Dhunt Nov 02 '15 at 15:26
  • I also added a new fiddle which will update without reloading page – Dhunt Nov 02 '15 at 15:50
0

With PHP you could use:

<div id="zillow-4" style="height:50px;"><a class="button " href="<?= (date('G') >= 14) ? '#' : 'updateScheduleRequest.php?slotid=4&amp;timeremain=110&amp;current_date=2015-11-02&amp;empnum=702' ?>">Assign Slot 4</a></div>

0

The question was using php and js

you'd create the logic with php first

$time = // what time?

then

@ref: http://stackoverflow.com/questions/10276133/how-to-disable-html-links
unixmiah
  • 3,081
  • 1
  • 12
  • 26