Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Thanked 1 Time in 1 Post

    using include or read to fill a textarea; need to swap files onchange of selectbox

    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> 

  2. #2
    Regular Coder
    Join Date
    Aug 2004
    Thanked 1 Time in 1 Post
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts