i don't know how to refresh a textarea.
if i have a text file opened on this textarea and i entre some lines into this file, i want to refresh my textarea in ..second automaticaly ..to see the new lines..

<textarea id="chat" rows='38' cols='189'>
<?php
$file1 = "test.txt";
$file2 = fopen($file1,"r");
while(! feof($file2))
  {
  echo fgets($file2)."<br/>";
  }
fclose($file2);
?>
</textarea>

i need help please

You need to user asynchronous javascript for this to happen.. Take a look at jquery. This is a good library to start with.

you have a solution using jquery ?

I can create a solution using jquery, as you can too.

what do you mean, you want to refresh the textarea? Is this after save the file or as you are editing the file? You can create a function with php to opend and edit a file, and then use ajax to call the function and load the saved data.

i want to refresh the textarea after saving some lines into the text file
(the text file is opened into the textarea,so after editing this file the new lines appears into the textarea)

Can you post the code you are working with so we can see what you are doing?

my code open & show all lines into "test.txt",
so the problem is, if i add some lines into my file i can't see the new lines into the textarea before i refresh the page... i want to refresh just the textarea to show all new lines thats it :)

<textarea id="tt" rows='38' cols='189'>
<?php
$file1 = "test.txt";
$file2 = fopen($file1,"r");
while(! feof($file2))
  {
  echo fgets($file2)."<br/>";
  }
fclose($file2);
?>
</textarea>

my code open & show all lines into "test.txt",
so the problem is, if i add some lines into my file i can't see the new lines into the textarea before i refresh the page... i want to refresh just the textarea to show all new lines thats it :)

<textarea id="tt" rows='38' cols='189'>
<?php
$file1 = "test.txt";
$file2 = fopen($file1,"r");
while(! feof($file2))
  {
  echo fgets($file2)."<br/>";
  }
fclose($file2);
?>
</textarea>

Looks like you are having trouble working it out so I will make an attempt for you.

This should open your file, allow you to edit the file, and save to the file.

Place all this code in one page.

<?php
    function insert_records($input)
    {
        $file = "test.txt";
        $fh = fopen($file, 'w') or die("can't open file");
        fwrite($fh, $input);
        fclose($fh);  
        return true;  
    }

    function read_records()
    {
        $handle = @fopen("test.txt", "r");
        if ($handle) {
            while (($buffer = fgets($handle, 4096)) !== false) {
                echo $buffer;
            }
            if (!feof($handle)) {
                echo "Error: unexpected fgets() fail\n";
            }
            fclose($handle);
        }
    }

    if( isset($_POST['save_file']) ){
       $updated = insert_records($_POST['editor']);   
       if($updated == true){
        echo 'file has been updated';           
       }else{
        echo 'file has not been updated';
       }
    }



?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><textarea name="editor" rows="30" cols="100"><?php read_records(); ?></textarea></p>
<p><input type="submit" name="save_file" value="Save Changes" /></p>
</form> 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.