Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: Save <textarea> results into *.txt file

  1. #1
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Question Save <textarea> results into *.txt file

    Hi!

    Can you save the results of a <textarea> to a *.txt file? Or maybe a *.htm or *.html file by pushing a button?

    I saw it once in the "Windows Vista Upgrade Advisor" so I think It's possible

    But is it?

    I would really appreciate it if I can get the script for it
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  2. #2
    Join Date
    Jun 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi,

    You could use the below code to write the contents of the <textarea> to a textfile. Here the ActiveXObject to write to the file.As per the coding NewFile.txt will be created under the C drive, and all <textarea> content will be placed in it.

    <html>
    <head>
    <script language="javascript">
    function WriteToFile()
    {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var s = fso.CreateTextFile("C:\\NewFile.txt", true);
    var text=document.getElementById("TextArea1").innerText;
    s.WriteLine(text);
    s.WriteLine('***********************');
    s.Close();
    }
    </script>

    </head>
    <body>
    <form>
    <div>
    <textarea id="TextArea1"
    height: style="width: 588px; height: 90px" 90px">We are a leading provider of software components and tools for the Microsoft .NET platform. Powerful and feature-rich, Syncfusion’s broad range of products are vital to mission-critical applications in organizations ranging from small businesses to multinational Fortune 100 companies. -www.syncfusion.com
    </textarea><br />
    <input id="Button1" type="button" value="Write" onclick="WriteToFile()"/>
    </div>
    </form>
    </body>
    </html>

    Let me know if you have any doubts.

    Regards,
    Valli

    [www.syncfusion.com
    http://www.syncfusion.com/faq/aspnet/default.aspx]

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you're stupid enough to use ActiveX in your websites, thereby royally cheesing off at least 30% of your visitors and causing a massive popup box to appear warning the rest that your site is trying to do something unsafe, go right ahead!

    If, however, you're a sane and intelligent being, you have two options here: cookies or server-side storage. The latter is preferable, since it won't expire or be deleted, but you may not have server-side scripting support on your server.

    NewFile.txt will be created under the C drive
    I don't have a "C drive." In fact, even Windows users might not have a "C drive."
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Try this!!

    Hey try this: http://calle.ioslo.net/testing/textarea-save/

    Uses cookies to store contents. And is better than using any Server side complicated code.

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    And is better than using any Server side complicated code.
    Server-side is always a better idea, since it ensures data integrity.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Twey for me (who is very bad at server side languages) it's really complicated.(you've seen it isn't it?? In the PM?? I couldn't even solve that simple problem. ). But anyways I am learning PHP and that's better than not knowing any server side language.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Twey for me (who is very bad at server side languages) it's really complicated.
    That's fine, but it's not a good idea to recommend that other people avoid them just because you don't understand them.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    By the way Twey did you realize that this reply textarea can actually perform events when Ctrl+B is pressed?? It actually does override the default firefox bookmark event. Any ideas how it is done?? I'd be appreciated if you could find it out. And by the way I never said that avoid it what I meant was that this code is simpler than that of server side languages and is easily usable. I am sorry If I said anything wrong.

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I agree with Twey here.

    I'm not sure if you want the file stored on the server or on the user's harddrive, but either way, you should use server side. It really isn't that complex. This is a simple code.

    You have two options:
    1. Code it to save to a text file on the server. Done.
    2. Code it to output the text file to the user, so they can save it as they want. This won't force anything onto their system (usually a bad idea), and will be fairly easy still.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    And by the way I never said that avoid it what I meant was that this code is simpler than that of server side languages and is easily usable.
    It was "better" I had an objection to.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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