javascript

I am learning java script. I have an external .js script and an embedded script in my files. It is not showing the date values or the comments.  I have the external file and then the .htm file below. Does the order need to be different?

.js-javascrip filet--

function XmasDays(thisDate) {
   var XMYear=thisDate.getFullYear();
   var XMDay=new Date("December, 25, 2005");
   XMDay.setFullYear(XMYear);
   var dayTotal=(XMDay-thisDate)/(1000*60*60*24);
   dayTotal=Math.round(dayTotal);
   return dayTotal;
}

function showDate(thisDate) {
var thisWDay=thisDate.getDay();
var thisDay=thisDate.getDate();
var thisMonth=thisDate.getMonth();
var thisYear=thisDate.getYear();
var monthName=new Array(12);
monthName[0]="January";
monthName[1]="February";
monthName[2]="March";
monthName[3]="April";
monthName[4]="May";
monthName[5]="June";
monthName[6]="July";
monthName[7]="August";
monthName[8]="September";
monthName[9]="October";
monthName[10]="November";
monthName[11]="December";
var wdayName=new Array(7);
wdayName[0]="Sunday";
wdayName[1]="Monday";
wdayName[2]="Tuesday";
wdayName[3]="Wednesday";
wdayName[4]="Thursday";
wdayName[5]="Friday";
wdayName[6]="Saturday";
dateString="weekday, month day, year";
document.write(wdayName[thisWDay]+", "+monthName[thisMonth]+" "+thisDay+", "+thisYear);  
}

------------------------------------------------------------
.htm file--
<html>
<head>

<title>North Pole Novelties</title>
<link href="styles2.css" rel="stylesheet" type="text/css" />

<script type="text/javascript"src="library2.js">showDate();</script>

</head>

<body>
<table id="npn" cellpadding="5" cellspacing="0">
<tr>
<!-- Company Hyperlinks -->
<td id="links" rowspan="4" valign="top">
   <a href="#">Home Page</a>
   <a href="#">Shopping Cart</a>
   <a href="#">Your Account</a>
   <a href="#">Contact Us</a>
   <a href="#" class="newgroup">Angels</a>
   <a href="#">Cards</a>
   <a href="#">Collectibles</a>
   <a href="#">Creches</a>
   <a href="#">Garland</a>
   <a href="#">Gift Wraps</a>
   <a href="#">Lights</a>
   <a href="#">Nutcrackers</a>
   <a href="#">Ornaments</a>
   <a href="#">Santas</a>
   <a href="#">Trains</a>
   <a href="#">Trees</a>
   <a href="#">Villages</a>
   <a href="#">Wreaths</a>
</td>

<!-- Company Logo -->
<td id="logo">
   <img src="logo.jpg" alt="North Pole Novelties" />
</td>
<!-- Days until Christmas -->
<td id="daycell">

<script language="JavaScript">
<!--HIDE FROM INCOMPATIBLE BROWSERS
function date() {
var today="December 24,2007";
var niceDate=today.showDate();
var daysleft=today.XMasDays();
document.write(niceDate +"<br/>");

if(daysLeft>1)  {

document.write("Only", +daysLeft + "days until Christmas")

} else if (daysLeft==1) {

document.write("Last Day for Christmas Shopping")

}
else {

document.write.("Happy Holidays from North Pole Novelties")

}

//STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>

</td>
</tr>

<tr>
<!-- Articles about the company -->
<td colspan="2">
   <table cellspacing="4" cellpadding="4">
   <tr>
   <!-- Welcome message -->
   <td id="firstcol" valign="top">
      <p class="firstp"><img src="bells.jpg" alt="" style="float: left" />
      Welcome to our online store. Consider us your complete holiday
      store. Whether you're a collector or simply looking for a beautiful
      piece to treasure for years, you'll find it at NPN. Please click on
      one of the many links to explore all we have to offer.</p>

   <!-- Latest news -->
      <h3>News Flash!</h3>
      <p>North Pole Novelties is proud to announce a new line of
      <b>Lasseter Old Towne Village collectible houses</b>.
      Start building your collection of these wonderful miniature
      porcelain houses and shops. </p>
      <p>Each model has accessories to enhance the collection. Be sure to
      order extra trees, fences, street lights and signs to bring activity
      and a festive atmosphere to your miniature town.</p>
   </td>

   <!-- Information about the company -->
   <td id="secondcol" valign="top">
      <h3>Who Are We?</h3>
      <p>
      <img src="watkins.jpg" alt="" style="float: right; margin: 0px 0px 15px 15px" />
      Located in Seton Grove, Minnesota, North Pole Novelties is one of the
      oldest and largest holiday stores in the country. The store was founded
      in 1968 by <b>David Watkins</b> (shown here). Today, David, his family,
      and over 300 employees manage the daily operation of making the holiday
      season last all year.</p>
      <p>The store itself is the size of two football fields and attracts
      visitors from around the world. If you can't pay us a visit, order our
      catalogue. We will deliver to any spot in the United States and
      overseas. In a rush? We can deliver your order overnight! We also
      gift wrap.</p>
   </td>
   </tr>
   </table>
</td>
</tr>

<tr>
<!-- Contact Information -->
<td id="contact" colspan="2">
   <b>North Pole Novelties</b> |
   25 Oakdale Avenue |
   Seton Grove, MN 53112 |
   (404) 555-1225
</td>
</tr>
</table>

</body>
</html>

pgmtklAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZvonkoSystems architectCommented:
First of all is this NOT valid HTML tag usage:
<script type="text/javascript"src="library2.js">showDate();</script>

THis is correct:
<script type="text/javascript"src="library2.js"></script>




0
ZvonkoSystems architectCommented:
The rest of your scripts is full of errors. Even when errors are corrected is the logic of the script returning same day for actual day and christmass.

If it helps then check this:
library2.js:
function XmasDays(thisDate) {
   var XMYear=thisDate.getFullYear();
   var XMDay=new Date("December, 25, 2005");
   XMDay.setFullYear(XMYear);
   var dayTotal=(XMDay-thisDate)/(1000*60*60*24);
   dayTotal=Math.round(dayTotal);
   return dayTotal;
}

function showDate(thisDate) {
var thisWDay=thisDate.getDay();
var thisDay=thisDate.getDate();
var thisMonth=thisDate.getMonth();
var thisYear=thisDate.getYear();
var monthName=new Array(12);
monthName[0]="January";
monthName[1]="February";
monthName[2]="March";
monthName[3]="April";
monthName[4]="May";
monthName[5]="June";
monthName[6]="July";
monthName[7]="August";
monthName[8]="September";
monthName[9]="October";
monthName[10]="November";
monthName[11]="December";
var wdayName=new Array(7);
wdayName[0]="Sunday";
wdayName[1]="Monday";
wdayName[2]="Tuesday";
wdayName[3]="Wednesday";
wdayName[4]="Thursday";
wdayName[5]="Friday";
wdayName[6]="Saturday";
dateString="weekday, month day, year";
 return (wdayName[thisWDay]+", "+monthName[thisMonth]+" "+thisDay+", "+thisYear);  
}


html:
html>
<head>

<title>North Pole Novelties</title>
<link href="styles2.css" rel="stylesheet" type="text/css" />

<script type="text/javascript"src="library2.js" ></script>

</head>

<body>
<table id="npn" cellpadding="5" cellspacing="0">
<tr>
<!-- Company Hyperlinks -->
<td id="links" rowspan="4" valign="top">
   <a href="#">Home Page</a>
   <a href="#">Shopping Cart</a>
   <a href="#">Your Account</a>
   <a href="#">Contact Us</a>
   <a href="#" class="newgroup">Angels</a>
   <a href="#">Cards</a>
   <a href="#">Collectibles</a>
   <a href="#">Creches</a>
   <a href="#">Garland</a>
   <a href="#">Gift Wraps</a>
   <a href="#">Lights</a>
   <a href="#">Nutcrackers</a>
   <a href="#">Ornaments</a>
   <a href="#">Santas</a>
   <a href="#">Trains</a>
   <a href="#">Trees</a>
   <a href="#">Villages</a>
   <a href="#">Wreaths</a>
</td>

<!-- Company Logo -->
<td id="logo">
   <img src="logo.jpg" alt="North Pole Novelties" />
</td>
<!-- Days until Christmas -->
<td id="daycell">

<script language="JavaScript" >
<!--HIDE FROM INCOMPATIBLE BROWSERS
function date() {
  var today= new Date("December 24,2007");
  var niceDate = showDate(today);
  var daysLeft = XmasDays(today);
  document.write(niceDate +"<br/>");
  if(daysLeft>1)  {
    document.write("Only", +daysLeft + "days until Christmas")
  } else if (daysLeft==1) {
    document.write("Last Day for Christmas Shopping")
  } else {
    document.write("Happy Holidays from North Pole Novelties")
  }
}

date();
//STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>

</td>
</tr>

<tr>
<!-- Articles about the company -->
<td colspan="2">
   <table cellspacing="4" cellpadding="4">
   <tr>
   <!-- Welcome message -->
   <td id="firstcol" valign="top">
      <p class="firstp"><img src="bells.jpg" alt="" style="float: left" />
      Welcome to our online store. Consider us your complete holiday
      store. Whether you're a collector or simply looking for a beautiful
      piece to treasure for years, you'll find it at NPN. Please click on
      one of the many links to explore all we have to offer.</p>

   <!-- Latest news -->
      <h3>News Flash!</h3>
      <p>North Pole Novelties is proud to announce a new line of
      <b>Lasseter Old Towne Village collectible houses</b>.
      Start building your collection of these wonderful miniature
      porcelain houses and shops. </p>
      <p>Each model has accessories to enhance the collection. Be sure to
      order extra trees, fences, street lights and signs to bring activity
      and a festive atmosphere to your miniature town.</p>
   </td>

   <!-- Information about the company -->
   <td id="secondcol" valign="top">
      <h3>Who Are We?</h3>
      <p>
      <img src="watkins.jpg" alt="" style="float: right; margin: 0px 0px 15px 15px" />
      Located in Seton Grove, Minnesota, North Pole Novelties is one of the
      oldest and largest holiday stores in the country. The store was founded
      in 1968 by <b>David Watkins</b> (shown here). Today, David, his family,
      and over 300 employees manage the daily operation of making the holiday
      season last all year.</p>
      <p>The store itself is the size of two football fields and attracts
      visitors from around the world. If you can't pay us a visit, order our
      catalogue. We will deliver to any spot in the United States and
      overseas. In a rush? We can deliver your order overnight! We also
      gift wrap.</p>
   </td>
   </tr>
   </table>
</td>
</tr>

<tr>
<!-- Contact Information -->
<td id="contact" colspan="2">
   <b>North Pole Novelties</b> |
   25 Oakdale Avenue |
   Seton Grove, MN 53112 |
   (404) 555-1225
</td>
</tr>
</table>
</body>
</html>


0
ZvonkoSystems architectCommented:
Now I see what you are doing!!!
Check this html script section:
<script language="JavaScript" >
<!--HIDE FROM INCOMPATIBLE BROWSERS
function date() {
  var today= new Date();
  var niceDate = showDate(today);
  var daysLeft = XmasDays(today);
  document.write(niceDate +"<br/>");
  if(daysLeft>1)  {
    document.write("Only", +daysLeft + "days until Christmas")
  } else if (daysLeft==1) {
    document.write("Last Day for Christmas Shopping")
  } else {
    document.write("Happy Holidays from North Pole Novelties")
  }
}

date();
//STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>


0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

flipzCommented:
You are also not calling the date() function (which I would rename to something like displayDate() anyway). If you just want to function to fire right away then put the line date(); (or displayDate(); if you rename the function) just before your closing script tags like this:


displayDate();
//STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>

There may be other issues - post your results after making the changes (including Zvonko's).
0
Michel PlungjanIT ExpertCommented:
So script:
function formatDate() {
  var today= new Date();
  var niceDate = showDate(today);
  var daysLeft = XmasDays(today);
  document.write(niceDate +"<br/>");
  if(daysLeft>1)  {
    document.write("Only ", +daysLeft + " days until Christmas")
  } else if (daysLeft==1) {
    document.write("Last Day for Christmas Shopping")
  } else {
    document.write("Happy Holidays from North Pole Novelties")
  }
}

function XmasDays(thisDate) {
   var XMYear=thisDate.getFullYear();
   var XMDay=new Date(XMYear,11,25);
   var dayTotal=(XMDay-thisDate)/(1000*60*60*24);
   dayTotal=Math.round(dayTotal);
   return dayTotal;
}
var monthName="January,February,March,April,May,June,July,August,September,October,November,December".split(',');
var wdayName="Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".split(',');
function showDate(thisDate) {
  var thisWDay=thisDate.getDay();
  var thisDay=thisDate.getDate();
  var thisMonth=thisDate.getMonth();
  var thisYear=thisDate.getYear();
  return (wdayName[thisWDay]+", "+monthName[thisMonth]+" "+thisDay+", "+thisYear);  
}



and where you want it:

<script language="JavaScript" >
<!--HIDE FROM INCOMPATIBLE BROWSERS
formatDate();
//STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pgmtklAuthor Commented:
Thanks. It is working when i changed the embedded script code below.  In the top hand of the page when i run it it displays as "Monday, March 19, 2007undefined" . Everything is defined, where is this error coming from?


<script language="JavaScript" >
<!--HIDE FROM INCOMPATIBLE BROWSERS
function date() {
  var today= new Date();
  var niceDate = showDate(today);
  var daysLeft = XmasDays(today);
  document.write(niceDate +"<br/>");
  if(daysLeft>1)  {
    document.write("Only", +daysLeft + "days until Christmas")
  } else if (daysLeft==1) {
    document.write("Last Day for Christmas Shopping")
  } else {
    document.write("Happy Holidays from North Pole Novelties")
  }
}

date();
//STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
0
pgmtklAuthor Commented:
I found what was wrong, a return statement. works now. thanks for the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.