View Full Version : using include or read to fill a textarea; need to swap files onchange of selectbox

09-23-2004, 01:00 PM
hi. the following works fine for the most part; it displays a textfile in a textarea and saves user changes onsubmit - i can get it to save to any of the three files i'm referencing, and can get it to display any single one of them, but i'm trying to get it to swap the contents of the textarea onchange of the selectbox - do i need js for this or can php react to an onchange event by itself?

i think i'm way overdoing this because of my inability - all i'm trying to do is allow a user to edit three text files stored serverside. i suspect there's a ridiculously easy way to do this that i'm just not aware of; if that's not the case i'd appreciate any direction as to how to accomplish what i'm trying with the below code.

the bit that's troublesome is red.


$filename = ($selbx);
if($submit && $string){
$textfile= fopen($filename,'w+');
if(! $textfile){
fputs($textfile, $string);
<form method=post action="<? echo $PHP_SELF; ?>" ?>
<select size=1 name=selbx>
<option value=1.txt>page1</option>
<option value=2.txt>page2</option>
<option value=3.txt>page3</option>
<textarea rows=10 cols=20 name=string>
<?php @readfile($selbx); ?>
<input type=submit name=submit value=write to file>

09-23-2004, 02:24 PM
Your problem is that PHP cannot react on clientside-events and javascript cannot read/write from/to a file on the server.

What you need to do, is put the selectbox in a html-form of it's own, with submission in the onchange event. U can then rebuild the page from the server, based on the input from the selectbox.