Javascript question
Need someone to look at this piece of HTML code and tell me why only a portion of my javascript code executes. The code is very small and fits into the "Hello World" complexity.
This happens in IE 11, Firefox 26.5, and Safari. Neither browser recognizes my javascript other then the Alert command.
Here's the code that works:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Untitled Document</title>
</head>
<body>
<SCRIPT language="JavaScript">
<!--
alert("alert-aliens attacking");
document.write("alert-aliens attacking");
document.write("hello")
//-->
</script>
</body>
</html>
The Alert box comes up properly.
=========================================
When I run the following code;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Displaying Times and Dates</title>
</head>
<body>
<h1>Current Date and Time</h1>
<script type="text/javascript" >
alert("alert-aliens attacking");
document.write("alert-aliens attacking");
Now1 = New Date();
localtime1 = now1.Tostring();
utctime1 = now1.toGMTString();
document.write("<strong>Local Time:<strong> '
+ Localtime1 + '
");
document.write("<strong>UTC Time:</strong> " + utctime1);
</script>
</body>
</html>
Only the H1 displays. Nothing else works. Not even the Alert. Am I missing something?
Any assistance would be greatly appreciated.
|