PDA

View Full Version : script changes by day of week


Ricky158
03-25-2003, 10:52 PM
hello my helpful homies (sorry, couldnt think of another H word to use there ;) )

this is what i'm looking for....

for sunday-thursday the "special" background music script will not be used, but fridays and saturdays, it will. the script is as following...


<form><table border=0 bordercolor=black><tr><th>
<font face="verdana"><font size=1><font color=white>
Background Music</font></th></tr></b><tr><td>
<center><embed src = "bgmusic.mp3" autostart =
"true" loop = "false" volume = "50%" height = "45"
width = "145">

^^ i know that script could be simplified, but it is an old script that i've been using from a tutorial website.

i hope that's descriptive enough.

i want to do this because as of now, i removed the script entirely, because it f*ed up my bandwidth limit. i figure that playing the background music on two popular nights will be enough to please the visitors and also please my bandwidth limit.

thanks a lot.

chrismiceli
03-25-2003, 11:40 PM
try this

<script type="text/javascript">
dte = new Date();
day = dte.getDay();
if(day==6||day==5) {
document.write(your script here);
}
else document.write(regular script);
</script>

Ricky158
03-26-2003, 12:49 AM
i dont think it works. i had my clock set to today, and it didnt show the alternative script. then i changed my clock to friday and it still didnt do anything. :(

glenngv
03-26-2003, 02:07 AM
can you post your code? I think chrismiceli's code is ok.

Ricky158
03-26-2003, 10:18 PM
the testing page is here.... http://www.angelfire.com/extreme4/waterwars/tst9394.html

where the double space is, there should be the alternative script, or at least the music box (if on a friday or saturday).

also, wouldnt "day 5" be thursday, and "day 6" be friday? considering it being a 7 day week.

chrismiceli
03-26-2003, 11:49 PM
no, all things programming start at zero, in this case sunday is 0, in my original post, i put saturday and friday, it should be five and 4.

Ricky158
03-26-2003, 11:51 PM
so could that be the problem? or maybe it needs to be told what 5 and 6 mean. does it already know that 5 means friday, or day 5, and 6 is saturday, or day 6? just making sure. hehe. i'll go back to the directory and swap the 5 and 6

Ricky158
03-26-2003, 11:53 PM
in any case, this is the script i used. maybe i cant put HTML in the ()'s??

<script type="text/javascript">
dte = new Date();
day = dte.getDay();
if(day==5||day==6) {
document.write(<form><table border=0 bordercolor=black><tr><th>
<font face="verdana"><font size=1><font color=white>
Background Music</font></th></tr></b><tr><td>
<center>
<embed src = "/extreme4/waterwars/bgmusic.mp3" autostart =
"true" loop = "false" volume = "50%" height = "45"
width = "145">
);
}
else document.write(Background Music not available until Friday
and Saturday, due to excessive bandwidth consumption.);
</script>

chrismiceli
03-27-2003, 12:00 AM
change

Originally posted by Ricky 158
<script type="text/javascript">
dte = new Date();
day = dte.getDay();
if(day==5||day==6) {
document.write(<form><table border=0 bordercolor=black><tr><th>
<font face="verdana"><font size=1><font color=white>
Background Music</font></th></tr></b><tr><td>
<center>
<embed src = "/extreme4/waterwars/bgmusic.mp3" autostart =
"true" loop = "false" volume = "50%" height = "45"
width = "145">
);
}
else document.write(Background Music not available until Friday
and Saturday, due to excessive bandwidth consumption.);
</script>

to this

<script type="text/javascript">
dte = new Date();
day = dte.getDay();
if(day==5||day==6) {
document.write("<form><table border=0 bordercolor='black'><tr><th>
<font face='verdana'><font size=1><font color='white'>
Background Music</font></th></tr></b><tr><td>
<center>
<embed src='/extreme4/waterwars/bgmusic.mp3' autostart=
'true' loop='false' volume='50%' height='45'
width='145'>"
);
}
else document.write("Background Music not available until Friday
and Saturday, due to excessive bandwidth consumption.");
</script>

Ricky158
03-27-2003, 12:02 AM
ahhhh.... quotation marks. precisely. i'll test it out....

Ricky158
03-27-2003, 12:04 AM
nope. i get the same problem as before. i changed the day to saturday, and still, nothing happened. must be something besides the quotes.

glenngv
03-27-2003, 01:37 AM
make sure you don't have line breaks in between string literals and the script is inside the body tag. you can also turn on error notification so that you can see the errors produced. I visited your site and 2 syntax errors occurred.

try:

<body>
<script type="text/javascript">
dte = new Date();
day = dte.getDay();
if(day==5||day==6) {
str = '<table border="0" bordercolor="black"><tr><th>';
str += '<font face="verdana" size="1" color="white">';
str += 'Background Music</font></th></tr></table>';
str += '<center><embed src="/extreme4/waterwars/bgmusic.mp3" autostart="true" ';
str += 'loop="false" volume="50%" height="45" width="145"></center>';
document.writ(str);
}
else document.write("Background Music not available until Friday and Saturday, due to excessive bandwidth consumption.");
</script>
</body>

just remove the line breaks between string literals that this forum may produce when displaying this post.

Ricky158
03-27-2003, 08:49 PM
that one worked for the regular text message (the non-friday and saturday message) but when i changed my clock to friday, it did the same thing as last time, and didnt work.

Skyzyx
03-27-2003, 09:54 PM
[code]

Change this:
document.writ(str);

to this:
document.write(str);

glenngv
03-28-2003, 01:07 AM
Oopps typo..Thanks Skyzyx :o

Ricky158
03-28-2003, 01:51 AM
every time i load the page on a friday or saturday clock setting, i get an error message and internet explorer has to terminate and it causes a big stink. any possible reasons why??

glenngv
03-28-2003, 02:53 AM
what's the error message?
is the code inside the body tag?

try putting an alert to check if the condition is satisfied

if(day==5||day==6) {
alert('here!');
...

Ricky158
03-28-2003, 03:28 AM
it's not a syntax error or something like that. when my status bar message changes to "Downloading [music URL]..." i get a message like "IEXPLORER.EXE has generated an error and will be shut down by Windows."

glenngv
03-28-2003, 04:01 AM
the error is in the <embed> tag. try <bgsound> for IE, and <embed> for Netscape.

<bgsound id="BGSOUND_ID" loop="1" src="/extreme4/waterwars/bgmusic.mp3" />