Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-17-2011, 03:55 AM   PM User | #1
paffley
New Coder

 
Join Date: Sep 2010
Posts: 86
Thanks: 24
Thanked 0 Times in 0 Posts
paffley is an unknown quantity at this point
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
paffley is offline   Reply With Quote
Old 07-17-2011, 08:44 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
Not quite
Code:
if (day == 0) { 
  if((hour>= 9) && (hour<= 17)) {
    $('#Shape1').hide(); 
  } else {
    $('#Shape1').show(); 
  }
}
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
paffley (07-18-2011)
Old 07-17-2011, 11:41 AM   PM User | #3
paffley
New Coder

 
Join Date: Sep 2010
Posts: 86
Thanks: 24
Thanked 0 Times in 0 Posts
paffley is an unknown quantity at this point
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
paffley is offline   Reply With Quote
Old 07-17-2011, 12:00 PM   PM User | #4
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,827
Thanks: 9
Thanked 685 Times in 679 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
Looks like you're just missing a closing }) there to close

Code:
$(document).ready(function{...
SB65 is online now   Reply With Quote
Users who have thanked SB65 for this post:
paffley (07-18-2011)
Old 07-17-2011, 01:52 PM   PM User | #5
paffley
New Coder

 
Join Date: Sep 2010
Posts: 86
Thanks: 24
Thanked 0 Times in 0 Posts
paffley is an unknown quantity at this point
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
paffley is offline   Reply With Quote
Old 07-17-2011, 02:03 PM   PM User | #6
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,827
Thanks: 9
Thanked 685 Times in 679 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
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
SB65 is online now   Reply With Quote
Users who have thanked SB65 for this post:
paffley (07-18-2011)
Old 07-17-2011, 02:17 PM   PM User | #7
paffley
New Coder

 
Join Date: Sep 2010
Posts: 86
Thanks: 24
Thanked 0 Times in 0 Posts
paffley is an unknown quantity at this point
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
paffley is offline   Reply With Quote
Old 07-18-2011, 02:02 AM   PM User | #8
paffley
New Coder

 
Join Date: Sep 2010
Posts: 86
Thanks: 24
Thanked 0 Times in 0 Posts
paffley is an unknown quantity at this point
EDIT - i worked my other problem out, thanks


regards,
paffley

Last edited by paffley; 07-18-2011 at 02:11 AM..
paffley is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:39 PM.


Advertisement
Log in to turn off these ads.