Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using CSS or javascript to schedule code

Status
Not open for further replies.

TechLearningCurve

Technical User
Mar 27, 2004
2
US
I am looking for a script that will enable me to load content based on a day of the week. The content will be written in jscript and I want the page to call up a different jscript based on a calendar date. Any suggestions?
 
I don't know about jscript, but with javascript, you could use the onLoad event handler as a <body> tag attribute and call a javascript function that tests the day, date, hour, or whatever. Based on the return values of your function you would then call different content or redirect to different pages.

There's always a better way. The fun is trying to find it!
 
better to do it using a server-parsed script.

what server technology do you have available?

<marc> i wonder what will happen if i press this...[ul][li]please tell us if our suggestion has helped[/li][li]need some help? faq581-3339[/li][/ul]
 
OK, the best way is to use the php date function to work out the day of the week, then an if statement to execute ana ction (include content, whatever).

Code:
[COLOR=blue]<?php

  $today [COLOR=green]=[/color] date[COLOR=green]([/color]"l"[COLOR=green])[/color];

  if [COLOR=green]([/color]$today [COLOR=green]==[/color] "Monday"[COLOR=green])[/color] [COLOR=green]{[/color]
    [COLOR=orange]/* execute monday's stuff */[/color]
   [COLOR=green]}[/color]  elseif [COLOR=green]([/color]$today [COLOR=green]==[/color] "Tuesday"[COLOR=green])[/color] [COLOR=green]{[/color]
    [COLOR=orange]/* execute tuesday's stuff */[/color]
   [COLOR=green]}[/color]  elseif [COLOR=green]([/color]$today [COLOR=green]==[/color] "Sunday"[COLOR=green])[/color]  [COLOR=green]{[/color]
    [COLOR=orange]/* execute sunday's stuff */[/color]
   [COLOR=green]}[/color]  else [COLOR=green]{[/color]
    [COLOR=orange]/* do some serious debugging :) */[/color]
   [COLOR=green]}[/color]
?>  
[/color]

remember that the date function can return a good many things, so there may be something more appropriate than date("1") for this task.

a similar working example uses the php include function:
Code:
[COLOR=blue]<?php

  $today [COLOR=green]=[/color] date[COLOR=green]([/color]"l"[COLOR=green])[/color];
  $today [COLOR=green].=[/color] ".php";
  include $today;

>?
[/color]

<marc> i wonder what will happen if i press this...[ul][li]please tell us if our suggestion has helped[/li][li]need some help? faq581-3339[/li][/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top