Java Script Help

Discussion in 'Web Design & Coding' started by PseudoKiller, Apr 18, 2004.

  1. PseudoKiller

    PseudoKiller Zug Zug

    Messages:
    3,858
    Location:
    Ice Crown Citadel
    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>
    
     
  2. Lee

    Lee OSNN Proxy

    Just adapt what I have pasted here for your document.

     
  3. PseudoKiller

    PseudoKiller Zug Zug

    Messages:
    3,858
    Location:
    Ice Crown Citadel
    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
     
  4. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    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>
     
  5. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    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>
     
  6. Lee

    Lee OSNN Proxy