SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im trying to use a .js file to store text that will be displayed in a small window. I tried to do a test in a regular window but i keep getting an error saying that my external variable is undefined. what am i doing wrong.
    Below are the two files.

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <SCRIPT LANUAGE="JavaScript" SRC="mytext.js"></SCRIPT>

    <SCRIPT LANUAGE="JavaScript" type="text/javascript">
    <!--
    var mytext = text;
    -->
    </SCRIPT>

    </head>

    <body bgcolor="#FFFFFF" text="#000000">
    <SCRIPT LANUAGE="JavaScript" >
    <!--
    document.write(mytext);
    -->
    </SCRIPT>


    </body>
    </html>

    mytext.js (External .js file)
    <!-- hide script from old browsers


    var text ="this is the text that should be inserted into the window whenever This source file is called lets see if it works";

    // end hiding script from old browsers -->


    please can someone help.

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works ok for me (IE5 and Opera 5/Windows). Are you sure all the file paths and variable names are correct?

    One thing I'm not sure is ok is the first line in the external js file.

    Code:
    <!-- hide script from old browsers
    I'm not sure if you can use this in a js file. Maybe someone who's got more javascript experience than myself can see the problem.

    What line is the error on?

    Shane

  3. #3
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well the problem is that it does not show any failures, but the text is not written on the page. I was also wondering though, because im not testing on an actual server, but on my desktop, do you think that i would have any problems there, i mean i have both files in the same folder and run from there.


    The reason i ask this is because i can test this on my server, but i wont know for sure if its a problem with the server or the code.

    I'm lost right now man, i cant figure out whats wrong.

    Im running iis5 on win2k, so i dont know if there is any special setting that i need for the server itself, but as i said i figured i could run the scripts on my desktop without doing all that. Im have no clue, please help..................

    leerie

  4. #4
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmmm, strange.

    I'm testing on my desktop too and it works ok. I'm using your code as I just cut and pasted it. I've just tested it with N6 and that works ok too.

    My js experience is limited so I can't offer any other help.

    Shane

  5. #5
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you said it works from your desktop as is. I cant believe it now im getting an error on line 9, saying that 'text' is undeclared. This is not cool

    at least i know its not my coding or server thats gone ******. I doubt its my browser, ie5, and i also tried it with netscape and it still doesnt work.

  6. #6
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey shane i found out what the problem was. i feel stupid saying it out loud, but what happened was i was using windows notepad to write the script, and even though i used .js it saved the file as mytest.js.txt. Thanks for all the help man.

    leerie


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
  •