...

View Full Version : Selected text file into textarea



zoobie
10-02-2003, 11:40 PM
How, if possible, would I insert a text or a .txt file into a form's textarea? Thanks

<form name="sara" etc>
<select onchange="this.form.comments.textfile=this.options[this.selectedIndex].value;">
<option value="info.txt">Info</option>
<option value="info2.txt">Info2</option>
</select>
<textarea name="comments"></textarea>
</form>

liorean
10-02-2003, 11:51 PM
You can use <http://codingforums.com/showthread.php?s=&threadid=14463> for it, or you can use the DOM methods (or proprietary XML methods) of including files. Then there's the Remote Scripting through Frame/IFrame/Object tags, but that gets complicated.

zoobie
10-03-2003, 04:49 AM
No simple way to do this besides selecting a link a page before the textarea one?

liorean
10-03-2003, 07:00 AM
Well, you can preload the files if you like, and then write their contents out in the textarea when the user choses a file. Really, the only yhing that interface does is load the file into memory.

zoobie
10-03-2003, 08:47 AM
How about an example?
Also, would this textarea within an iframe be editable?

main.html
<iframe name="pete" src="page.html">

page.html
<body>
<form>
<textarea>
Prepopulated text here
</textarea>
</form>
</body>

I'm a little thick tonight...
Thanks

AlaskanWebDesig
10-17-2004, 03:28 PM
Hello everyone, I have read alot about the following post so I hope everyone is able to get this working. It works great and is very simple to edit. It allows you to have a .txt file opened in a 'textarea', then edit it, and then save the text file again.

Hope this helps everyone!

You will need to create a .txt file I called mine datafile.txt
Make you change the files Permissions to 666 so that it can be changed by the server.

Put this in one file ( I called it Form.php )

// form.php
// email me if you would like me to send you the code for then one form per page...
<?
$fp = fopen("datafile.txt","r");
$contents = fread($fp,filesize("datafile.txt"));
fclose($fp);
?>

<form action="Process.php" method=post>
<textarea name="file_content" rows="10" cols="42"><? echo str_replace("\\","",$contents); ?></textarea>
<input type=submit name=submit value=Update>
</form>

I put this in a file called Process.php
// Process.php
<?
$fp = fopen("datafile.txt","w");
fwrite($fp,$_POST['file_content']);
fclose($fp);
?>
<?php include("http://www.InteriorWebHosting.com") ?>
// I also used a php page insert to insert the form page to make it more user friendly... :)
// Admin@InteriorWebHosting.com

Brandoe85
10-17-2004, 05:50 PM
Hello everyone, I have read alot about the following post so I hope everyone is able to get this working. It works great and is very simple to edit. It allows you to have a .txt file opened in a 'textarea', then edit it, and then save the text file again.

Hope this helps everyone!

You will need to create a .txt file I called mine datafile.txt
Make you change the files Permissions to 666 so that it can be changed by the server.

Put this in one file ( I called it Form.php )

// form.php
// email me if you would like me to send you the code for then one form per page...
<?
$fp = fopen("datafile.txt","r");
$contents = fread($fp,filesize("datafile.txt"));
fclose($fp);
?>

<form action="Process.php" method=post>
<textarea name="file_content" rows="10" cols="42"><? echo str_replace("\\","",$contents); ?></textarea>
<input type=submit name=submit value=Update>
</form>

I put this in a file called Process.php
// Process.php
<?
$fp = fopen("datafile.txt","w");
fwrite($fp,$_POST['file_content']);
fclose($fp);
?>
<?php include("http://www.InteriorWebHosting.com") ?>
// I also used a php page insert to insert the form page to make it more user friendly... :)
// Admin@InteriorWebHosting.com

Last time I checked this was a javascript forum.

AlaskanWebDesig
10-19-2004, 12:26 AM
Brando,
I may have posted php code into a javascript thread, but this solves the problem that Zoobie had/has... :thumbsup:

If people can't use php, I found a really cheap host provider at www.InteriorWebHosting.com



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum