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 8 of 8
  1. #1
    New Coder
    Join Date
    Sep 2010
    Posts
    88
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Jquery day and time help

    Hi guys, I need some help and info with this code I have. It shows an id on certain days e.g. 0=sunday and so on...

    Code:
        var rightNow = new Date(); 
        var day = rightNow.getDay();
        if (day == 0) { 
          $('#Shape1').show(); 
        } 
        if (day == 1) { 
          $('#Shape1').hide(); 
        } 
        if (day == 2) { 
          $('#Shape1').hide(); 
        } 
        if (day == 3) { 
          $('#Shape1').hide(); 
        } 
        if (day == 4) { 
          $('#Shape1').hide(); 
        } 
        if (day == 5) { 
          $('#Shape1').hide(); 
        } 
        if (day == 6) { 
          $('#Shape1').hide(); 
        } 
    });
    Everything works fine but what im needing now is to add a time function to make Shape1 to .hide at a certain time of the day if the #Shape1 is set to .show on lets say 'sunday'.

    I add the var:

    Code:
    var hour = rightNow.getHours();
    But this is the part im stuck with, heres my attempt...

    Code:
        if (day == 0) { 
          $('#Shape1').show(); 
        }
        else {    
              if((hour>= 9) && (hour<= 17)) {
          $('#Shape1').hide(); 
        }

    Any help is hugly appreciated.


    Regards,
    paffley

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Not quite
    Code:
    if (day == 0) { 
      if((hour>= 9) && (hour<= 17)) {
        $('#Shape1').hide(); 
      } else {
        $('#Shape1').show(); 
      }
    }

  • Users who have thanked devnull69 for this post:

    paffley (07-18-2011)

  • #3
    New Coder
    Join Date
    Sep 2010
    Posts
    88
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Hi dev, thanks for the response but some how I cannot get it to hide...

    this is what I have so far..

    Code:
    $(document).ready(function() {
        var rightNow = new Date(); 
        var day = rightNow.getDay();
        var hour = rightNow.getHours();
        if (day == 0) { 
        if((hour>= 9) && (hour<= 17)) {
        $('#Shape1').hide(); 
      } else {
        $('#Shape1').show(); 
      }
    }
    Regards,
    paffley

  • #4
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 726 Times in 720 Posts
    Looks like you're just missing a closing }) there to close

    Code:
    $(document).ready(function{...

  • Users who have thanked SB65 for this post:

    paffley (07-18-2011)

  • #5
    New Coder
    Join Date
    Sep 2010
    Posts
    88
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SB65 View Post
    Looks like you're just missing a closing }) there to close

    Code:
    $(document).ready(function{...
    Hi SB, thanks for the reply, sorry im not understanding, do you mean the closing bracket at the end of the function or at the end of the full script?

    I can see the open bracket just after the document ready function but im not ure were to place the closing bracket.


    Regards,
    paffley

  • #6
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 726 Times in 720 Posts
    Code:
    $(document).ready(function() {//open doc ready function
       var rightNow = new Date(); 
       var day = rightNow.getDay();
       var hour = rightNow.getHours();
       if (day == 0) { //start of if day condition
          if((hour>= 9) && (hour<= 17)) {//start of if hour condition
             $('#Shape1').hide(); 
          } else {//if hour else condition
             $('#Shape1').show(); 
          }//end of if hour else condition
       }//end of if day condition
    });//end of doc ready function

  • Users who have thanked SB65 for this post:

    paffley (07-18-2011)

  • #7
    New Coder
    Join Date
    Sep 2010
    Posts
    88
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Thank you SB! I appreciate your help very much, im still learning jquery and what you just posted helped me very much! Thanks again, your a star.



    Regards,
    paffley

  • #8
    New Coder
    Join Date
    Sep 2010
    Posts
    88
    Thanks
    24
    Thanked 0 Times in 0 Posts
    EDIT - i worked my other problem out, thanks


    regards,
    paffley
    Last edited by paffley; 07-18-2011 at 02:11 AM.


  •  

    Posting Permissions

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