SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: Javascripters, come in please...
-
Nov 12, 2000, 09:32 #1
I have a script which displays the current date in each page of mysite. In all pages i call the script as follows
<script language="javascript" src="http://mydomain.com/scripts/dispdate.js"></script>
This works fine on IE but not in NS.
The error it gave me in NS is :
JavaScript Error:
http://mydomain.com/scripts/dispdate.js, line
1:
illegal character.
9
.^
The line 1 of the JS file is
var montharray=new Array(all months);
However if i include contents of the script file directly in each page without using the src attribute, it works fine in both IE and NS.
Whats the problem?
-
Nov 12, 2000, 13:58 #2
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The outer limits to reachmk: come in please
Offhand I would say "all months". What is it? a variable with a space (illegal, use an underline -- all_months -- or mixed case -- allMonths)? an IE-specific keyword & variable? (still illegal, because it works for IE, it doesn't make it proper).
If it is a variable, where is it defined -- in the main page?
If the respelling doesn't work, I'm going to need to know the answers to the above before I can help.
transmission over, for now
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Nov 12, 2000, 20:52 #3
- Join Date
- Oct 2000
- Location
- Austin, TX
- Posts
- 1,438
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I believe he was using "all months" as an abbreviation in his post for "January","February","March","April", etc.
-
Nov 13, 2000, 03:16 #4
Yep, Anarchos is right. Heres the full code if that may help.
Code:var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December"); var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); var today=new Date(); var todayy=today.getYear(); if (todayy < 1000) { todayy+=1900;} var todaym=today.getMonth(); var todayw=today.getDay(); var todayd=today.getDate(); var todayh=today.getHours(); var todaymin=today.getMinutes(); var todaysec=today.getSeconds(); if (todayh > 12) {todayh=todayh-12; ampm="P.M.";} else {ampm="A.M."} if (todaymin <= 9) { todaymin="0"+todaymin;} if (todaysec <= 9) { todaysec="0"+todaysec;} var todaystring=dayarray[todayw]+", "+montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec+" "+ampm document.write(todaystring);
-
Nov 13, 2000, 17:46 #5
- Join Date
- Oct 2000
- Posts
- 304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by reachmk
I call the script as follows...
<script language="javascript" src="http://mydomain.com/scripts/dispdate.js"></script>
This works fine on IE but not in NS.
The error it gave me in NS is :
JavaScript Error:
http://mydomain.com/scripts/dispdate.js, line 1: illegal character. 9 .^
However if I include contents of the script file directly in each page without using the src attribute, it works fine in both IE and NS. What's the problem?
Give a shot at opening that .js file in plain old NotePad and retyping the beginning of it.
-
Nov 14, 2000, 20:29 #6
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi reachmk,
Again, I have to agree with etLux. I just cut and pasted the code you posted and ran it under NN 4.7 -- no problem; it printed the current day, month, etc. The only other thing I can think of is: script tags -- there should be none. A js file cannot have any HTML tags of any sort in it unless they are embedded within a javascript variable.
VinnyWhere the World Once Stood
the blades of grass
cut me still
-
Nov 15, 2000, 00:12 #7
- Join Date
- Oct 2000
- Posts
- 304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Good point, Vincent, and one I often forget to mention to newcomers to the art.
For the record:
A .js file is *not not not* and "include" file.
There must be nothing whatsoever but the script itself in the .js file -- and it must be in strict plain-text format.
Bookmarks