SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Highlight current hour

    Hi All

    I am having a stab at adding functionality to a calendar script i have made.

    I have an appointments diary but want to highlight the current hour (segmented in 15 minute slots) so people can visually see the current window.

    I have had a go at putting some code together but failed miserably.

    I wonder if I could have a few pointers on how to do this from some of you gurus.

    Here is what I have currently, dont laugh!

    Code:
    <script language="javascript">
    
    function highlight(){
    
    theTime=setTimeout('highlight()',1000);
    
    document.td.id.getHours="bgcolor='#cccccc'";
    			
    }
    </script>
    </head>
    
    <body>
    <table width="100" border="0" cellspacing="3" cellpadding="2">
      <tr>
        <td id="8">8:00</td>
      </tr>
      <tr>
        <td id="9">9:00</td>
      </tr>
      <tr>
        <td id="10">10:00</td>
      </tr>
      <tr>
        <td id="11">11:00</td>
      </tr>
      <tr>
        <td id="12">12:00</td>
      </tr>
      <tr>
        <td id="13">13:00</td>
      </tr>
    </table>
    
    </body>

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use the javascript date object to retrieve the current hour of the day. For e.g.

    now = new Date();
    current_hour = now.getHours();

    The current_hour variable could then be used to find the corresponding td that needs to be highlighted.

  3. #3
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Thanks for posting

    That makes sense, I will give it a go.

    Regarding the finding of the corresponding <td> cell what is the best method of identifying it? (I used the id="???" inside th etag as a bit of a guess) and what is the best way of 'injecting' the text into the table and removing the old highlight?

    Thanks in advance

    Keith

  4. #4
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone got an idea of how to identify a <td> cell?

    would <td id="1"> Some data</td> work?

    Keith


Bookmarks

Posting Permissions

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