By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,251 Members | 2,764 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,251 IT Pros & Developers. It's quick & easy.

How to display a text file using Javascript

P: n/a
Is there any sample code to use Javascript to load and display a text
file?

It will be best if the user can select files using some kind of
explorer. If that's complex, a text box to specify the file name will
be fine as well. Once a text file is selected, I just need to display
it in a text box.

Thanks for the help.

Apr 3 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ji*********@gmail.com wrote:
Is there any sample code to use Javascript to load and display a text
file? I'm not quite sure what your senario is. I assumed that you have make
your files accessible directly on web or through some sort of CGI
program. You have several ways to do the job and the easiest one is to
simply have them rendered in a frame/iframe with their respective urls.

It will be best if the user can select files using some kind of
explorer. If that's complex, a text box to specify the file name will
be fine as well. Once a text file is selected, I just need to display
it in a text box.


There's no such a thing as a 'explorer' in JavaScript which can be used
to browse server-side files. You have to design an 'explorer' page and
have a server program generating the file list.

The way I metioned above is to display your files in a frame/iframe. You
can css-style the frames to make them look exactly like a textbox (but
you will not be able to edit on them of course). If a textbox is really
required in your design, either you generate a page with file content
wrapped in textarea tag on the server-side, or on the client-side you
may consider using HTTPRequest object in JavaScript to fetch those files
and feed the text response to textarea element dynamically.

Hope this would help.
-- Elan Hung
Apr 3 '06 #2

P: n/a

Check around for Asynchronous JavaScript, aka Ajax, will be the way
to do it.

Danny
Apr 3 '06 #3

P: n/a
ji*********@gmail.com wrote:
Is there any sample code to use Javascript to load and display a text
file?
<URL:http://jibbering.com/faq/#FAQ2_3>
<URL:http://jibbering.com/faq/#FAQ2_4>
<URL:http://groups.google.de/groups?as_q=load+OR+save+file&as_ugroup=comp.lang. javascript&scoring=d&filter=0>
It will be best if the user can select files using some kind of
explorer.


<input type="file">
PointedEars
Apr 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.