PDA

View Full Version : Blockage Problem


Scripter
12-03-2003, 07:37 PM
I have these javascripts here but when they are viewed the second one blocks the first from showing after it asks for the name.

Script:
=====================================

<script language="JavaScript" type="text/javascript">
<!-- Lets Begin
window.alert('Hi and welcome to my page.');
name = window.prompt('Please enter your name','');
todaysDate = new Date();
timenow=datetoday.getTime();
todaysDate.setTime(timenow);
thehour = todaysDate.getHours();
if (thehour > 17) display = "Evening";
else if (thehour >=12) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + " " + name);
document.write(greeting);
// The End -->
</script>
</center>

<script language="JavaScript" type="text/javascript">
var WeekdayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000) year = year + 1900;
document.write(WeekdayNames[time.getDay()] + ", " + lmonth + " ");
document.write(date + ", " + year);
// The End -->
</script>

gish
12-05-2003, 12:24 PM
thats because you have a variable error....

...
todaysDate = new Date();
.../ * you need to change this -> timenow=datetoday.getTime(); to */
todaysDate.getTime();
...

gish
12-05-2003, 12:25 PM
if you have show script errors tunred on from the browser, you can debug by reading what the errors are.

Scripter
12-05-2003, 09:41 PM
Damnit, thanks a lot for that fix. Thats what happens when you copy and paste and try to change a few things around. Thanks Gish

Oh one more thing can style sheets be inlcuded in javascript?

tobymiller
01-21-2004, 04:53 PM
Yes, just be sure you output them inline within the head of the document. Otherwise you may get random results.



<html>
<head>
<title>test</title>
<script type="text/javascript">
document.write('<style type="text/css">');
document.write('#mydiv { background-color:#ff0000; }');
document.write('</style>');
</script>
</head>
<body>
<div id="mydiv">hello</div>
</body>
</html>