Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple javascript is giving me an error

Status
Not open for further replies.

photoxprt1868

Programmer
Jul 22, 2005
76
0
0
US
hello,

I have this simple piece of code in my page to spit out the date and it's braking my page. Without it the page works great, but with it the page doesn't display becuase of a javascript error.

I have this on the body of the page

Code:
<SCRIPT language="JavaScript" TYPE="text/javascript">
<!--
// Set varible to the current date
var right_now=new Date();

// set variable to current month number (0-11)
var month_num = right_now.getMonth()

// set varible to the current day value (1-31)
var thedate=right_now.getDate()

// create an array for the month name
var month_name = new Array (
"January ",
"February ",
"March ",
"April ",
"May ",
"June ",
"July ",
"August ",
"September ",
"October ",
"November ",
"December ");

// Create a varible right_year with the current year
var right_year=right_now.getYear();
document.write("<b>");
document.write(month_name[month_num]);
document.write(right_year);
document.write("</b>");
</script>

thank you
 
it works for me too by itself, but as soon as I insert it into the page where I want to use it the it gives me an error.

It gives me a syntax error and it doesn't display anything.

I even put it in a server side include and nothing.
 
Perhaps you are not inserting it in the right place, or are including it incorrectly? Are you including a .js file? If so, you should not have the open and closing "script" tags.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Actually at first I just pasted that same code in the body of the page and wrapped it around a <div> tag. and that didn't work either.

If I were to separate some of the code in the <head> what would be the syntax to then show the current month and year in the body.

Thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top