www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Day of Week & getElementById = Simple?

Hybrid View

  1. #1
    Join Date
    Sep 2008
    Posts
    33

    resolved [RESOLVED] Day of Week & getElementById = Simple?

    I'm trying to use a very simple piece of Javascript code on a Ning site, but it's not working. Am I missing something obvious, or is it possible Ning is overwriting something?

    Any help would be greatly appreciated!

    The Javascript code is:

    Code:
    var d=new Date();
    var weekday=new Array(7);
    weekday[0]="Sunday";
    weekday[1]="Monday";
    weekday[2]="Tuesday";
    weekday[3]="Wednesday";
    weekday[4]="Thursday";
    weekday[5]="Friday";
    weekday[6]="Saturday";
    document.getElementById(weekday[d.getDay()])).style.display = 'block';
    The code is being called from the main page of the site here: http://time4mommy.com/

    The goal is to have different things show up each day of the week. I have 7 divs each with the name of the week like this...

    Code:
    <div id="Sunday" style="display: none;"></div>
    
    <div id="Monday" style="display: none;"></div>
    
    <div id="Tuesday" style="display: none;"></div>
    
    <div id="Wednesday" style="display: none;"></div>
    
    <div id="Thursday" style="display: none;"></div>
    
    <div id="Friday" style="display: none;"></div>
    
    <div id="Saturday" style="display: none;"></div>
    The Javascript code in the link above, theoretically, should display anything within the div with the id of the current day of the week. However, it's not doing that, so currently, I've changed Friday's div style to "display: block;"

    Am I just missing something really obvious? Or does Ning not like my code?

    Thanks in advance!

  2. #2
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    607
    The following line has too many right parenthesis:
    Code:
    document.getElementById(weekday[d.getDay()])).style.display = 'block';
    I think it should be:
    Code:
    document.getElementById(weekday[d.getDay()]).style.display = 'block';

  3. #3
    Join Date
    Sep 2008
    Posts
    33
    You are awesome! That was it! Thanks so much!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles