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 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2003
    Location
    Sunshine Coast, Australia
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Saving a text area to a file.

    Hi anyone who reads this

    Ive done some searching on the net but have been unsuccesful in possibly finding a way to save the contents of a Text Area or even a Text Field to a file onto my machine or the users machine.

    Does anyone know how to do this ? is it possible ?
    surely it is huh ->
    =======================
    'There are 10 types of people in the world, those who understand binary and those who do not."

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,015
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Javascript has no capability to write to a file. You need a server side language such as PHP or PERL to do this.

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP, Perl, ASP will do it easily, the thing that boggles me is that this topic was moved!?? To javascript!!

  • #4
    Regular Coder
    Join Date
    Jul 2003
    Location
    NJ - #29 if you must know
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was able to have javascript using active X save
    a text file to the clients machine, but it had problems.

    I have since started writing a file on the server side
    and using a link to the filename so when the user
    clicks on it, it downloads like any other file.

    Using the Active-X required too much tweaking of
    the security settings than I wanted.

    I don't have the coding anymore on what I used
    to write to the file.

    Sorry,

    George

  • #5
    piz
    piz is offline
    Regular Coder
    Join Date
    Jul 2002
    Location
    Barcelona
    Posts
    246
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here a Sample which saves the textarea-content in a textfile. It works with JavaScript and with VBScript, but only eith Internet Explorer.

    And, of course, the file is not saved on the computer where you are using the script from - not on the server who hostes this file.

    Code:
    <html>
    <head>
    	<title>Saving textarea to file - www.united-scripts.com</title>
    	<script language="vbscript">
    		sub save_text_vbs()
    			set fs = Createobject("Scripting.FileSystemObject")
    			file_location = "c:\textarea.txt"
    			set file = fs.CreateTextFile(file_location, True)
    			file.Write document.getElementById("text").value
    			file.close
    			document.getElementById("result").value = "File successfully saved in " & file_location
    		end sub
    	</script>
    	<script language="javascript">
    		function save_text_js()
    		{
    			var file_location = "c:/textarea.txt";
    			var fs = new ActiveXObject("Scripting.FileSystemObject");
    			file = fs.CreateTextFile(file_location, true);
    			file.write(document.getElementById("text").value);
    			file.close();
    			document.getElementById("result").value = "File successfully saved in " + file_location;
    		}
    	</script>
    </head>
    
    <body>
    	<textarea cols="40" rows="10" id="text" style="width:400px;"></textarea><br>
    	<input type="button" onclick="save_text_vbs()" value="Save using VBScript (only in IE)" style="width:400px;"><br>
    	<input type="button" onclick="save_text_js()" value="Save using JavaScript" style="width:400px;"><br>
    	<input type="text" id="result" style="width:400px;border: 0px solid white;">
    </body>
    </html>
    (This will only work if your scuritiy settings are permitting creating ActiveX Objects by Brwoser Scripting)

    Saludo
    piz

  • #6
    Regular Coder
    Join Date
    Jul 2003
    Location
    NJ - #29 if you must know
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes, those were the links to the vbcode/active x
    I was using.

    The problem I encountered, was when the file
    existed already. Sometimes the file would
    get overwritten, other times the existing data
    wouldn't get overwritten. It was inconsistant.

    That may be OS dependent, or maybe it was
    something at the time that was IE/VB/Javascript
    problem that may have been corrected in later
    releases.

    Unless this is on an intranet, with all the potential
    security issues with activeX and websites, as stated
    it's almost not worth the use.

    But, it did work, and wasn't hard to implement.

    George


  •  

    Posting Permissions

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