We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Help with a script.
Topic Started: Nov 27 2005, 09:06 AM (193 Views)
Calabur
ルイス
[ *  *  *  *  *  *  * ]
So i decided to learn javascript, i then tested what i knew already and the code worked fine, but now it doesn't.

http://s13.invisionfree.com/Tranquil_note/index.php

That's how it displays currently(view bottom, on the maintitle).

I want it to display a message that says; "Today is (insert day here) Insert (morning/afternoon here), on a maintitle image.

The code i'm using is.

Code:
 
<table border="0" width="100%" <tr><td class="maintitle"> <script type="text/javascript">
var d= new Date()
theDay=d.getDay()
switch (theDay)
{
case 0:
var d = new Date()
var time = d.getHours()
if (time<12)
{
document.write("Today is sunday morning")
}
else if (time>12 && time<18)
{
document.write("<b>Today is sunday afternoon</b>")
}
else
{
document.write("<b>Today is sunday, have a nice sleep.</b>")
}

case 1:
var d = new Date()
var time = d.getHours()
if (time<12)
{
document.write("Today is monday morning")
}
else if (time>12 && time<18)
{
document.write("<b>Today is monday afternoon</b>")
}
else
{
document.write("<b>Today is monday, have a nice sleep.</b>")
}

case 2:
var d = new Date()
var time = d.getHours()
if (time<12)
{
document.write("Today is tuesday morning")
}
else if (time>12 && time<18)
{
document.write("<b>Today is tuesday afternoon</b>")
}
else
{
document.write("<b>Today is tuesday, have a nice sleep.</b>")
}

case 3:
var d = new Date()
var time = d.getHours()
if (time<12)
{
document.write("Today is wednesday morning")
}
else if (time>12 && time<18)
{
document.write("<b>Today is wednesday afternoon</b>")
}
else
{
document.write("<b>Today is wednesday, have a nice sleep.</b>")
}

case 4:
var d = new Date()
var time = d.getHours()
if (time<12)
{
document.write("Today is thursday morning")
}
else if (time>12 && time<18)
{
document.write("<b>Today is thursday afternoon</b>")
}
else
{
document.write("<b>Today is thursday, have a nice sleep.</b>")
}

case 5:
var d = new Date()
var time = d.getHours()
if (time<12)
{
document.write("Today is friday morning")
}
else if (time>12 && time<18)
{
document.write("<b>Today is friday afternoon</b>")
}
else
{
document.write("<b>Today is friday, have a nice sleep.</b>")
}

case 6:
var d = new Date()
var time = d.getHours()
if (time<12)
{
document.write("Today is saturday morning")
}
else if (time>12 && time<18)
{
document.write("<b>Today is saturday afternoon</b>")
}
else
{
document.write("<b>Today is saturday, have a nice sleep.</b>")
}




}
</script>
</td></tr></table>
Offline Profile Quote Post Goto Top
 
Epsilekt
Member Avatar
Member
[ *  *  *  *  *  * ]
So you want to grab the date and then use it?

Try this.

Code:
 
<script language="javascript">var day2 = new Date().getDay();switch(day2) {case 0: var day = 'Sunday'; break;case 1: var day = 'Monday'; break;case 2: var day = 'Tuesday'; break;case 3: var day = 'Wednesday'; break;case 4: var day = 'Thursday'; break;case 5: var day = 'Friday'; break;case 6: var day = 'Saturday';}

/* You have now made the variable 'day' with the value of the name of today. */

var time2 = new Date().getHours();if(time2 < 12) {var greeting = 'morning.';}if(time2 >= 12) {var greeting = 'afternoon.';}if(time2 > 18) {var greeting = 'evening, have a nice sleep.';}

/* You have now made the variable 'greeting' with the value of what people in London would say when they say hi to you. */

document.write('Today is ' + day + ' ' + greeting);

</script>


Uncrushed version:

Code:
 
<script language="javascript">
var day2 = new Date().getDay();

switch(day2) {
case 0: var day = 'Sunday'; break;
case 1: var day = 'Monday'; break;
case 2: var day = 'Tuesday'; break;
case 3: var day = 'Wednesday'; break;
case 4: var day = 'Thursday'; break;
case 5: var day = 'Friday'; break;
case 6: var day = 'Saturday';
}

/* You have now made the variable 'day' with the value of the name of today. */

var time2 = new Date().getHours();

if(time2 < 12) {
var greeting = 'morning.';
}
if(time2 >= 12) {
var greeting = 'afternoon.';
}
if(time2 > 18) {
var greeting = 'evening, have a nice sleep.';
}

/* You have now made the variable 'greeting' with the value of what people in London would say when they say hi to you. */

document.write('Today is ' + day + ' ' + greeting);

</script>
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply