SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast reachmk's Avatar
    Join Date
    Oct 2000
    Location
    UK
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    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
    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    You talkin to me? Anarchos's Avatar
    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.

  4. #4
    SitePoint Enthusiast reachmk's Avatar
    Join Date
    Oct 2000
    Location
    UK
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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);
    Thanks in advance for any help/suggestions.

  5. #5
    SitePoint Addict
    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?
    At a guess, you may have some extraneous "no-see-um" character caught in the beginning of your script file. While IE will tolerate this, NS will not.

    Give a shot at opening that .js file in plain old NotePad and retyping the beginning of it.

  6. #6
    SitePoint Guru Vincent Puglia's Avatar
    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.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  7. #7
    SitePoint Addict
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •