View Full Version : reading from an external .txt file

07-05-2003, 09:24 PM
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?

07-06-2003, 12:04 AM
Welcome to the forums. :thumbsup:

Why not an external JS file?

07-06-2003, 12:24 AM
I believe he wants to use it as a flat database kind of file. (possibly automatically generated).


07-06-2003, 06:37 AM
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

07-06-2003, 03:43 PM
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.

07-06-2003, 04:30 PM
and how can i read from an external js file?

07-06-2003, 05:22 PM
Hi pseudo

Use this:


<script src="XXXXXXX.js">


It's as easy as that!!!!

The best thing to do would be to look at this EXCELLENT tutorial (http://www.w3schools.com/js/js_whereto.asp) on javascript which will probably explain everything you need to know.

Hope this helps.

07-06-2003, 05:26 PM
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:eek:

07-06-2003, 06:05 PM
//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

07-06-2003, 06:17 PM
var exa = $read(textfile.txt));
var pse = new Array($exa);
var pse = new Array($read(textfile.txt));

in the text file it would be


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

07-06-2003, 06:22 PM
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