View Full Version : Javascript Not Displaying
TennBikeBerk
07-20-2005, 10:33 PM
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:
<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.
kram 2.0
07-20-2005, 10:51 PM
It's working fine here, at least in MSIE. I'm presuming you're all writing this within the body tags.
kram
TennBikeBerk
07-20-2005, 11:12 PM
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. (http://www.miswebdesign.com/resources/articles/xhtml-special-character-references.html)
kram 2.0
07-21-2005, 01:02 PM
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
mairving
07-21-2005, 01:20 PM
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.
TennBikeBerk
07-21-2005, 03:58 PM
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:
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?
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.