Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically populate a textarea from a text file?

Status
Not open for further replies.

ChillAPAC

Technical User
May 21, 2002
37
US
Is it possible to create a textarea and have it be populated from a text file? If the text file exists, read the text and display. If the text file doesn't exist, display default text?

If anyone has any examples please post.

Thanks in advance.

Bill
 
Here's something that works for me with IE and Opera.

Basically, load text file into hidden iframe. Read contents of hidden iframe and load into textarea. NOTE that iframe contents seem to automatically get <PRE></PRE> tags put around it, which have to be removed.

Code:
<html>
<head>
<script>
function getIt()
{
  var text = document.frames[0].document.body.innerHTML;

  //remove <PRE></PRE> tags
  text = text.substring(("<PRE>").length);
  text = text.substring(0, text.indexOf("</PRE>"));

  myText.value = text;
}//end getIt()
</script>
</head>
<body onload='getIt();'>
<textarea id='myText' rows='10' cols='60'></textarea>
<iframe src='text.txt' width='0' height='0'></iframe>
</body>
</html>

'hope this helps.

--Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
It is possible to create a textarea in html. It is also possible to prefill that text area with text. Html however cannot help you with loading of a file or providing logic to determine whether file exists or not. If file is on the server, then your preferred choice of server side scripting will help. If it is client side, then I guess you can work with javascript. Both solutions fall out of scope of this forum.
 
Oops! I sometimes forget I'm not in the JS forum when answering here!

Trying to stay honest,

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top