Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Selected text file into textarea

    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>
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    You can use <Importing file contents as JS string> 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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts
    No simple way to do this besides selecting a link a page before the textarea one?
    Last edited by zoobie; 10-03-2003 at 04:51 AM.
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    ColoRockyz
    Posts
    1,646
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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
    Zoobie or not Zoobie...That is the problem.
    <body onUnload="flush( ! )">

  • #6
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation HOWTO: Insert text into textarea and save it in PHP

    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

  • #7
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by AlaskanWebDesig
    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.

  • #8
    New to the CF scene
    Join Date
    Oct 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb hmm...

    Brando,
    I may have posted php code into a javascript thread, but this solves the problem that Zoobie had/has...

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


  •  

    Posting Permissions

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