Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Trying to hide/show website content for a few hours on certain days

    <html>
    <head>
    <script type="text/javascript">
    onload=function(){

    var rightNow = new Date();
    var day = rightNow.getDay();
    var hour = rightNow.getHours();
    var newDisplay = 'none';
    if(day==3 || day==4 || day==5 || day==6 || day==7 || day==1 || day==2) {
    if((hour>= 12) && (hour< 20)) {
    newDisplay = 'block';
    }
    }
    document.getElementById('test').style.display = newDisplay;
    }
    </script>

    </head>
    <body>

    <div id="test" style="display: inline; text-align: center;">
    hello
    </div>


    </body>
    </html>


    Why doesnt that work?

  • #2
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i added days 1 and 2 on at the end there just when i was tryign to find the problem

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,182
    Thanks
    23
    Thanked 603 Times in 602 Posts
    days run 0 to 6 not 1 to 7. Try this
    Code:
    if(day==3 || day==4 || day==5 || day==6 || day==7 || day==0 || day==2) {
    if(hour >= 8 && hour < 20) {
    		newDisplay = 'block';
    	}
    }
    FYI this text appears to the far left but when display is block; that and the text-align: center; will kick it to the center.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    marketgarden (04-21-2013)

  • #4
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi,

    The alignment I'm not worried about, its the remnant of a previous edit!.


    <html>
    <head>
    <script type="text/javascript">
    onload=function(){

    var rightNow = new Date();
    var day = rightNow.getDay();
    var hour = rightNow.getHours();
    var newDisplay = 'none';
    if(day==3 || day==4 || day==5 || day==6 || day==0 || day==1 || day==2) {
    if(hour >= 8 && hour < 20) {
    newDisplay = 'block';
    }
    }
    document.getElementById('test').style.display = newDisplay;
    }
    </script>

    </head>
    <body>

    <div id="test">
    hello
    </div>


    </body>
    </html>


    still doesnt appear to work for me on notepad, im still plugging away here. i know this should work as ive had it working in the distant past.

  • #5
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    oh hang on a second, i think it does work, whatever youve done to it...!

    Thank you very much! (for now )


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •