• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Java Script Help

P

PseudoKiller

Guest
#1
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
#2
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
#3
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 User
#4
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 User
#5
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 posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,962
Messages
673,240
Members
89,018
Latest member
timpage