Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cannot read src array

    I have an external file, TestVar.js with a single line.
    NewsA("This is a test.","test.pdf","TEST")

    Within my HTML I wish to use the array variables from TestVar.js, but can't seem to get them loaded for use. The following is what I have, but doesn't work. If I directly place the NewsA array in the script instead of trying to call it from the js it works just the way I want it, but I really need the external file. What am I doing wrong?

    *************

    Start of test 1
    <div style="text-align: center;"><font color="#ff0000">
    <script language="javascript">
    var NewsA=new Array();
    </script>
    <script type="text/javascript" src="TestVar.js" language="javascript"><font color="#ff0000">
    var NewsText = NewsA[0];
    var NewsPath = NewsA[1];
    var NewsLink = NewsA[2];
    document.write(NewsText);document.write(" <a href = "+NewsPath+">"+NewsLink+"</a>")</script><br>
    </font>
    </div>
    End of Test 1

    *********

    Coyote

  • #2
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    NewsA=("This is a test.","test.pdf","TEST")

    Why not have contents of TestVar.js be:
    Code:
    var NewsA=new Array();
    NewsA=["This is a test.", "test.pdf", "TEST"]
    document.write(NewsA[0]+' <a href="'+NewsA[1]+'">'+NewsA[2]+'</a>')
    and the markup look like this:

    Code:
    <div style="text-align: center;"><font color="#ff0000">
    <script type="text/javascript" src="TestVar.js"></script>
    <br></font></div>

  • #3
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The main reason is that there will be html illiterates who will be editing it. I would like it to have as little in it as possible that can be messed up.

  • #4
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, that's easy. Remember, declaring an array name and its contents equal creates the array. So, TestVar.js can be:
    Code:
    NewsA=["This is a test.", "test.pdf", "TEST"]
    and the markup:
    Code:
    <div style="text-align: center;"><font color="#ff0000">
    <script type="text/javascript" src="TestVar.js"></script>
    <script type="text/javascript">
    document.write(NewsA[0]+' <a href="'+NewsA[1]+'">'+NewsA[2]+'</a>')
    </script>
    <br></font></div>
    You cannot combine the two scripts in the markup because code written between the first script's opening and closing tags is executed before the code in its source file. This is still simpler than what you had and fulfills your requirement.

  • #5
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks to all.

    That got it.


  •  

    Posting Permissions

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