put this in an HTML doc.. and watch the fun...
of course, this is pure client side script. Currently without a PHP Perl, ASP coldfusion.... something.. to pull file information you cannot write information to a server from the client.
You may be able to <SCRIPT LANGUAGE="JavaScript" runat=server> but that will only work if you server has a
JS engine and you the engine is given permission to modify/add files on the server.
<html>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
/*var Path= 'c:\\documents and settings\\default\\desktop\\';
so you know what a path format has to be
the \\ translates to \ when javascript engine hits it*/
var Tristate = 0;
/*
0= ASCII text
-1= Unicode text
-2= system default*/
var ForWriting;
/*
8= append exsisting file
2= write exsisting file
1= read exsisting file*/
var Create= true;
/*true= if(file !exsist) {create}
false=if(file !exsist) {return error}*/
file = new ActiveXObject("Scripting.FileSystemObject");
/*declaring outside of funtion makes it global if you need to use recursive code*/
function news() {
ForWriting = 8;
text = file.OpenTextFile(/*Path+*/'news.txt', ForWriting, Create, Tristate);
text.Write(document.forms[0].textbox1.value+unescape('%0D%0A'));
/*%0D%0A is the escape code for linefeed carriage return
used this instead of a standard \n because notepad
doesnt display \n correctly. Wordpad, however, does.*/
text.Close();
}
function news2() {
ForWriting = 2;
text = file.OpenTextFile(/*Path+*/'news2.txt', ForWriting, Create, Tristate);
text.Write(document.form1.textbox1.value);
text.Close();
}
// -->
</SCRIPT>
</head>
<body>
<form name="form1" onSubmit="news();news2();return false;">
<input type="text" name="textbox1">
<input type="Submit" value="Update" name="update">
</form>
If you run this with <br>
line 1 then Update<br>
line 2 then Update<br>
line 3 then Update<br>
line 4 then Update<br>
<br>
You will get two files. <br>
news.txt looks like <br>
line 1 <br>
line 2 <br>
line 3 <br>
line 4 <br>
<br>
news2.txt looks like<br>
line 4<br>
<br>
<p>Indicating everytime the news function is called the file is added to, everytime the news2 function is called, the file is erased, then written with new data.</p>
<p>The form itself uses the onSumbit even to run the news() and news2() functions, then returns false to the form allowing it to stay on the same page. </p>
<p>By removing the action you will only run the onSubmit functions.</p>
</body>
</html>