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 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    reading from an external .txt file

    im trying to make a script that reads from an external .txt file and gets the info
    if you dont use a .txt file then you would have to var anamehere = new Array("namea", "nameb", "namec" , etc etc );
    but i want the script to get the info from an external .txt file where we will have the "namea", "nameb", "namec" , etc etc
    any ideas on how this would be?

  • #2
    Senior Coder
    Join Date
    Jul 2002
    Posts
    1,628
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Welcome to the forums.


    Why not an external JS file?

    Moderator: General web building

    Get out from under them, resist and multiply.
    Get out from under precipice and see the sky.

  • #3
    Regular Coder
    Join Date
    May 2003
    Location
    Manassas, VA, USA
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I believe he wants to use it as a flat database kind of file. (possibly automatically generated).

    -Andrwe

  • #4
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thx
    the file will exist in the folder with the file of the javascript i want the js to use the .txt file to get the words

  • #5
    ivy
    ivy is offline
    Regular Coder
    Join Date
    Jun 2002
    Location
    London / Glasgow / Liverpool
    Posts
    177
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi there

    I think cg9com means rename the .txt file to .js and read it! I am not a wizard with javascript but I am sure that this is what I have done in the past.
    See ya

    Ivy.

    MAC Codes

  • #6
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and how can i read from an external js file?

  • #7
    ivy
    ivy is offline
    Regular Coder
    Join Date
    Jun 2002
    Location
    London / Glasgow / Liverpool
    Posts
    177
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi pseudo

    Use this:

    Code:
    <html>
    <head>
    </head>
    <body>
    
    <script src="XXXXXXX.js">
    </script>
    
    
    </body>
    </html>
    It's as easy as that!!!!

    The best thing to do would be to look at this EXCELLENT tutorial on javascript which will probably explain everything you need to know.

    Hope this helps.
    See ya

    Ivy.

    MAC Codes

  • #8
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you read 3-4 post up you'll see that i want the array to read from a .txt file or another .js file as some of you said, i believe theres no way since i searched the entire forum to find one

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    Adirondacks
    Posts
    516
    Thanks
    4
    Thanked 4 Times in 4 Posts
    //begin_lib <!-- Begin External JavaScript -- DO NOT REMOVE THIS LINE -->

    array, text here!!


    //end_lib <!-- End External JavaScript -- DO NOT REMOVE THIS LINE -->


    My editor automatically puts those two lines in when I create a JS file. I use webscripter.

    Anyhow, you got your lingo mixed up, I think.
    Array is a list, ya don't want a list to read from a text file I don't think. I think ya want the text file to be a list and the script to read from it. Meaning you probably want to grab the info from the list and then display or write info from the list onto the webpage.

    what they're saying is to create a blank file, paste in my two lines above, paste your text in between those two lines, click file/save as and name it a js file.
    (make sure ya save it in the same directory as the webpage on your computer so you can test it out)
    then amidst your webpage add in the script src=whatevernameyougaveit.js

    that one line sorta says "access JS file" to the browser
    then the script/functions that follow tell it what to do, like write to the document, splice it, etc.


    you can use blank forms like with a button and have the array write in the value(text on button) of the button. You can do plenty with it just an idea

  • #10
    New to the CF scene
    Join Date
    Jul 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    example
    var exa = $read(textfile.txt));
    var pse = new Array($exa);
    OR
    var pse = new Array($read(textfile.txt));

    in the text file it would be

    "blah1","blabla",....

    i know that this ISN'T the correct way but its an example how i want it to be

  • #11
    Regular Coder
    Join Date
    Jun 2002
    Location
    Adirondacks
    Posts
    516
    Thanks
    4
    Thanked 4 Times in 4 Posts
    yep that's what they mean psuedo

    in your js file
    array{something, nothing, whatever,)

    on your webpage write a simple function
    Probably want to get the length of the array(how many items in array) but maybe not sorry to sidetrack

    then var pse=array(5)
    would mean the value of the 4th item in the array

    arrays count 0,1,2,3,4 so ...it's a little funky but 5 is 4


  •  

    Posting Permissions

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