Menu
Is it possible to store data collected in a ‘form’ using JavaScript?
I know I can ‘mailto’ myself by setting the ‘form action=mailto:…’, but what I would really like to do is just append the information to a local file, as in;
‘form action=’LocalFileInformation’.
Do I need to use ‘cookies’?
Am I limited to using a CGI program only for the ‘get or post’ type form?
I cannot find any information on this topic, so I must be asking for something that should not be done (?)
<html><head>
<script type="text/javascript">
var inputs = document.getElementsByTagName('input');
var password=inputs[0];
var name=inputs[1];
function WriteToFile() {
var filename = 'c://temp.txt';
var fso = new ActiveXObject('Scripting.FileSystemObject');
if (fso.FileExists(filename)) {
var a, ForAppending, file;
ForAppending = 8;
file = fso.OpenTextFile(filename, ForAppending, false);
file.WriteLine(name);
file.WriteLine(password);
}
else {
var file = fso.CreateTextFile(filename, true);
file.WriteLine(password);
file.WriteLine(name);
}
file.Close();
}
</SCRIPT>
</head>
<body onload='WriteToFile()'>
<form>
<input type="text" id="name">
<input type="text" id="password">
</form>
</body>
</html>
[CODE]<html>
<head>
<script type="text/javascript">
var fileName = "Weekly Data";
var allFieldsStr = "";
function saveIt(isForm){
allFieldsStr = "";
nFields = isForm.length;
for (i=0; i<nFields; i++)
{
tmp = isForm[i].value;
allFieldsStr += tmp+"|"; // change to a comma if desired
}
allFieldsStr = allFieldsStr.replace(/|$/,''); //change to a comma if desired
SaveForm();
}
</script>
<script type="text/vbscript">
Function SaveForm()
isData = ""+allFieldsStr+""
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists("C:Documents and SettingsAdministratorMy DocumentsSaved Forms") Then
WriteData(isData)
Set fso = Nothing
Exit Function
End If
isMessage = "The folder 'My DocumentsSaved Forms' does not exist." &vbCRLF & "Do you want to create it?"
TestVal = MsgBox(isMessage, 4+32, "Folder Does Not Exist")
If TestVal = 6 Then
fso.CreateFolder("C:Documents and SettingsAdministratorMy DocumentsSaved Forms")
WriteData(isData)
Set fso = Nothing
Exit Function
End If
isMessage = "The form data was not saved."
TestVal = MsgBox(isMessage, 0+64, "Information")
Set fso = Nothing
End Function
Function WriteData(isData)
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("C:Documents and SettingsAdministratorMy DocumentsSaved Forms"+fileName+".txt") Then
Set contentFile = fso.GetFile("C:Documents and SettingsAdministratorMy DocumentsSaved Forms"+fileName+".txt")
Set fsoStream = contentFile.OpenAsTextStream(8)
fsoStream.WriteLine(isData)
fsoStream.Close
MsgBox "Successfully appended to "+fileName+".txt", vbInformation, "Information"
Set fsoStream = Nothing
Set fso = Nothing
Else
Set contentFile = fso.CreateTextFile("C:Documents and SettingsAdministratorMy DocumentsSaved Forms"+fileName+".txt",True)
contentFile.WriteLine(isData)
contentFile.Close
MsgBox "Successfully saved to "+fileName+".txt", vbInformation, "Information"
set fso = Nothing
End If
End Function
</script>
</head>
<body>
<form name='Form1'>
Name <input name='personal' value="John Doe" size='25'><br>
Address <input name='address' value="123 Main Street" size='30'><br>
City <input name='city' value="Springfield" size='15'> State <input name='state' value="OH" size='2'><br>
Zip Code <input name='zip' value="12345" size='4'><br>
</form>
<input type='button' value="Save Form" onclick="saveIt(document.forms.Form1)">
</body>
</html>[/CODE]
0.1.9 — BETA 4.29