How to open and save text in html to file using javascript in HTML
I have a text box and two buttons
like
<form name="form1">
<textarea name="text1"> HTML Codes goes here </textarea>
<input type="button"> Open File
<input type="button"> Save File
</form>
when I click the Save button, I want the text in the text box to be saved (I want it to pop up in the Save As dialog box)
When I click "open", it should let me select any html or text file ... and load the text into a text file / htmlcode in my text area.
Found this code at http://www.dynamicdrive.com/forums/archive/index.php/t-10532.html
<html>
<head>
</head>
<body>
<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>
<form name="abc">
<textarea name="text">FIFA</textarea>
<button onclick="WriteToFile()">Click to save</Button>
</form>
</body>
</html>
this will work if the user allows the user to save the file ... and I forgot to say that all the files are on the client computer.
Thanx in advance
-Miss Subanki
+5