Java Script Help

  • Thread starter Thread starter PseudoKiller
  • Start date Start date
P

PseudoKiller

Guest
I am trying to get a javascript to display the current date including month, weekday, date and year.
There is a function for whether it is christmas and how many days till christmas ... seems I cant even get the damn this to display. I have gone over it several times and I cant find out whats wrong. Anyhelp would be appreciated.

Code:
<html>
<head>
<title>TEST</title>
<script language="JavaScript">
<!--- Hide from non-JavaScript browsers
function XmasDays(CurrentDay) {
   var XYear=CurrentDay.getFullYear();
   var XDay=new Date("December, 25, 2003");
   XDay.setFullYear(XYear);
   var DayCount=(XDay-CurrentDay)/(1000*60*60*24);
   DayCount=Math.round(DayCount);
return DayCount;
}
function MonthTxt (MonthNumber) {
   var Month=new Array();
   Month[1]="January";
   Month[2]="February";
   Month[3]="March";
   Month[4]="April";
   Month[5]="May";
   Month[6]="June";
   Month[7]="July";
   Month[8]="August";
   Month[9]="September";
   Month[10]="October";
   Month[11]="November";
   Month[12]="December";
return Month[MonthNumber];
 }
 function WeekDayTxt(WeekDayNumber) {
 var WeekDay=new array();
 WeekDay[1]="Sunday";
 WeekDay[2]="Monday";
 WeekDay[3]="Tuesday";
 WeekDay[4]="Wednesday";
 WeekDay[5]="Thursday";
 WeekDay[6]="Friday";
 WeekDay[7]="Saturday";
 return WeekDay[WeekDayNumber];
 }
// Stop hiding -->
</script>
<style>
</style>
</head>
<center><table width="600" cellpadding="5" cellspacing="0" border="1" bgcolor="white">
<tr>
<!--- Days until Christmas --->
<td valign="top" align="center" bgcolor="gold">
   <span style="font-size:small; font-weight:bold">
   <script language="JavaScript">
	  <!--- Hide from non-JavaScript browsers
	  var Now=new Date();
	  var ThisDay=Now.getDate();
	  var ThisMonth=Now.getMonth()+1;
	  var ThisYear=Now.getFullYear();
	  var DaysLeft=XmasDays(Now);
	  var MonthName=MonthTxt(ThisMonth);
	  var WeekDayName=WeekDayTxt(WeekDay);
	  
		if (DaysLeft > 1) {
 document.write(WeekDayName+","+MonthName +" "+ThisDay+"<br>");
 
	  } if (DaysLeft == 1) {
 document.write ("Last day for Christmas shopping");
 
	  } else {
 document.write ("Happy Holidays from North Pole Novelties");
 }
 
	  // Stop hiding --->
   </script>
   </span>
</center>
<body>
</html>
 
L

Lee

Guest
Just adapt what I have pasted here for your document.

<HTML>
<TITLE>Xmas Count Down</TITLE>
<BODY>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var date = new Date("December 25, 2004");
var description = "Xmas";
var now = new Date();
var diff = date.getTime() - now.getTime();
var days = Math.floor(diff / (1000 * 60 * 60 * 24));
document.write("<center><h3>")
if (days > 1) {
document.write(days + " days until " + description);
}
else if (days == 1) {
document.write("Only two days until " + description);
}
else if (days == 0) {
document.write("Tomorrow is " + description);
}
else {
document.write("It's" + description + "!");
document.write("</h3></center>");
}
// End -->
</script>
<!-- END OF SCRIPT -->


</body>
</html>
 
P

PseudoKiller

Guest
altough I appreciate what you have done... I still have to have the output be something like...

Tuesday, April 10, 2004
There are only 250 days till Christmas

I cant seem to get the output to be even close to that... grrrr
 

Khayman

I'm sorry Hal...
Political Access
Joined
6 Jan 2002
Messages
5,518
Hows this
Modified from Lee's code
Code:
<HTML>
<TITLE>Xmas Count Down</TITLE>
<BODY>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var date = new Date("December 25, 2004");
var description = "Christmas";
var now = new Date();
var diff = date.getTime() - now.getTime();
var days = Math.floor(diff / (1000 * 60 * 60 * 24));
var weekday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var monthname= new Array('January','February','March','April','May','June','July','August','September','October','November','December')
document.write(weekday[now.getDay()] + " ")
document.write(now.getDate() + " ")
document.write(monthname[now.getMonth()] + " ")
document.write(now.getFullYear() +"<br />")
if (days > 1) {
document.write("There are "+days + " days until " + description);
}
else if (days == 0) {
document.write("Tomorrow is " + description);
}
else {
document.write("It's" + description + "!");
}
// End -->
</script>
<!-- END OF SCRIPT -->


</body>
</html>
 

Khayman

I'm sorry Hal...
Political Access
Joined
6 Jan 2002
Messages
5,518
Or your one
Code:
<html>
<head>
<title>TEST</title>
<script language="JavaScript">
<!--- Hide from non-JavaScript browsers
function XmasDays(CurrentDay) {
   var XYear=CurrentDay.getFullYear();
   var XDay=new Date("December, 25, 2003");
   XDay.setFullYear(XYear);
   var DayCount=(XDay-CurrentDay)/(1000*60*60*24);
   DayCount=Math.round(DayCount);
return DayCount;
}
function MonthTxt (MonthNumber) {
   var Month=new Array();
   Month[1]="January";
   Month[2]="February";
   Month[3]="March";
   Month[4]="April";
   Month[5]="May";
   Month[6]="June";
   Month[7]="July";
   Month[8]="August";
   Month[9]="September";
   Month[10]="October";
   Month[11]="November";
   Month[12]="December";
return Month[MonthNumber];
 }
 function WeekDayTxt(WeekDayNumber) {
 var WeekDay=new Array();
 WeekDay[0]="Sunday";
 WeekDay[1]="Monday";
 WeekDay[2]="Tuesday";
 WeekDay[3]="Wednesday";
 WeekDay[4]="Thursday";
 WeekDay[5]="Friday";
 WeekDay[6]="Saturday";
 return WeekDay[WeekDayNumber];
 }
// Stop hiding -->
</script>
<style>
</style>
</head>
<center><table width="600" cellpadding="5" cellspacing="0" border="1" bgcolor="white">
<tr>
<!--- Days until Christmas --->
<td valign="top" align="center" bgcolor="gold">
   <span style="font-size:small; font-weight:bold">
   <script language="JavaScript">
	  <!--- Hide from non-JavaScript browsers
	  var Now=new Date();
	  var ThisDay=Now.getDay();
	  var ThisMonth=Now.getMonth()+1;
	  var ThisYear=Now.getFullYear();
	  var DaysLeft=XmasDays(Now);
	  var MonthName=MonthTxt(ThisMonth);
	  var WeekDayName=WeekDayTxt(ThisDay);
	  
		if (DaysLeft > 1) {
 document.write(WeekDayName+","+MonthName +" "+ThisDay+"<br>");
 
	  } if (DaysLeft == 1) {
 document.write ("Last day for Christmas shopping");
 
	  } else {
 document.write ("Happy Holidays from North Pole Novelties");
 }
 
	  // Stop hiding --->
   </script>
   </span>
</center>
<body>
</html>
 

Members online

No members online now.

Latest profile posts

Xie Electronic Punk Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. 🙁

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk Sazar Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz Electronic Punk Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk Sazar Electronic Punk wrote on Sazar's profile.
Where are you buddy?

Forum statistics

Threads
62,017
Messages
673,508
Members
5,636
Latest member
GLOCKTOR642
Back