Click to See Complete Forum and Search --> : Jscript filewriting


obviousunknown
07-27-2003, 06:39 PM
I know the basic syntax for writing to a text file using Jscript.

objText.WriteLine('Radom stuff')

the problem is that everytime it writes something new (a changing variable) it overwrites what ever was in the text file before.
Is there a way to only write to the next line instead of overwriting everything in the text file?

obviousunknown
07-27-2003, 11:57 PM
Here's what I have so far. I can open the file, I can display the file in the textarea and I can also save whatever is in the textbox into the file. But instead of overwriting anything, I want it to write a new line to the file and keep the old one as well.

<html>
<head>
<script type="text/jscript">
function savefile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("C:\\textfile.txt", true);
a.WriteLine(document.form1.text1.value);
a.Close();
}
function openfile()
{
var ForReading = 1
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.OpenTextFile("C:\\textfile.txt", ForReading);
document.form1.text2.value = a.ReadAll();
a.Close();
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="text1"><br>
<textarea name="text2"></textarea><br>
<a href="" onClick="openfile(); return false;">Open File</a><br>
<a href="" onClick="savefile(); return false;">Save File</a>
</form>
</body>
</html>

obviousunknown
07-28-2003, 03:38 PM
so what do i do?