Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 07-20-2005, 09:33 PM   #1
Member (8 bit)
 
Join Date: Jun 2004
Posts: 220
Javascript Not Displaying

On my website, I would like to use javascript to display the following:

"Happy [Day of week] and good [time of day], folks."

For example, if it were a Monday morning, it should output: "Happy Monday and good morning, folks."

Here is the code I have been unsuccessfully using:

HTML Code:
<script type="text/javascript">
var d=new Date()
var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
document.write("Happy " + weekday[d.getDay()] + " and ")
var time = d.getHours()
if (time < 12) 
{
document.write("good morning")
}
else if (time > 12 & time < 17)
{
document.write("good afternoon")
}
else
{
document.write("good evening")
}
document.write(", folks.")
</script>
Does anybody have an idea what the problem is? Thanks.
TennBikeBerk is offline   Reply With Quote
Old 07-20-2005, 09:51 PM   #2
Moderator
Staff
Premium Member
 
Join Date: Aug 2003
Location: Richmond, VA
Posts: 7,835
It's working fine here, at least in MSIE. I'm presuming you're all writing this within the body tags.

kram
__________________
"For today, goodbye. For tomorrow, good luck. And forever, Go Blue!"
University of Michigan President Mary Sue Coleman
kram 2.0 is offline   Reply With Quote
Old 07-20-2005, 10:12 PM   #3
Member (8 bit)
 
Join Date: Jun 2004
Posts: 220
Okay, that coding actually works for me too.

I changed the less than signs to actual signs, rather than "<" and also changed the greater than signs to actual signs, rather than ">" for my post.

How come these character references aren't working? It seems the corresponding entity references aren't working as well (">" and "<").

I am working in an XHTML 1.1 document, and W3C is cautioning me about using the raw "<" and ">" symbols.

Suggestions?

EDIT: Looks like this post isn't displaying things as I wanted it too. In my document, when I use (this will all be written out, so it doesn't get changed) ampersand, letter g, letter t, semicolon, to express a ">" symbol, rather than just using my keyboard, and pressing shift+,

I tried both character references and entity references in my code for my page, none of which work in Firefox.

See this page.

Last edited by TennBikeBerk; 07-20-2005 at 10:19 PM.
TennBikeBerk is offline   Reply With Quote
Old 07-21-2005, 12:02 PM   #4
Moderator
Staff
Premium Member
 
Join Date: Aug 2003
Location: Richmond, VA
Posts: 7,835
Quote:
Originally Posted by TennBikeBerk
Okay, that coding actually works for me too.

I changed the less than signs to actual signs, rather than "<" and also changed the greater than signs to actual signs, rather than ">" for my post.

How come these character references aren't working? It seems the corresponding entity references aren't working as well (">" and "<").

I am working in an XHTML 1.1 document, and W3C is cautioning me about using the raw "<" and ">" symbols.

EDIT: Looks like this post isn't displaying things as I wanted it too. In my document, when I use (this will all be written out, so it doesn't get changed) ampersand, letter g, letter t, semicolon, to express a ">" symbol, rather than just using my keyboard, and pressing shift+,

I tried both character references and entity references in my code for my page, none of which work in Firefox.
Alright - time out. You want to display the physical "<" sign and so you used Amperstand-G-T-SemiColon to express it. Why not just use the raw "<" if it's part of the coding? Do you need the "<" to physically display as part of the document.write ?

kram
kram 2.0 is offline   Reply With Quote
Old 07-21-2005, 12:20 PM   #5
Staff
Premium Member
 
mairving's Avatar
 
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
Quote:
Originally Posted by kram8806
Alright - time out. You want to display the physical "<" sign and so you used Amperstand-G-T-SemiColon to express it. Why not just use the raw "<" if it's part of the coding? Do you need the "<" to physically display as part of the document.write ?

kram
the < in this case is less than. the > is greater than. It could error with some verifiers but they are not correct.
__________________

Want to Make $$$$ with your Computer? No Risk! Simply press shift-4 four times in a row
mairving is offline   Reply With Quote
Old 07-21-2005, 02:58 PM   #6
Member (8 bit)
 
Join Date: Jun 2004
Posts: 220
I suppose I could just the raw symbols, since it is part of the coding. I do not need them to display as a part of a document.write.

Just as a note, it does work when I use the raw symbols, but when I use W3C's XHTML 1.1 validator, it says the page is valid, but I receive the following:
Quote:
Warning:
Line 52, column 9: character "<" is the first character of a delimiter but occurred as data

Warning:
Line 56, column 19: character "&" is the first character of a delimiter but occurred as data

Warning:
Line 56, column 26: character "<" is the first character of a delimiter but occurred as data
Should I just ignore the warnings, or is there something I can do to make my code both work, and not get any warnings?
TennBikeBerk is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 04:53 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2