My code is HTML with JavaScript, I can write to a text file using JavaScript (client side) but this is based on 1 item. I want to have multiple forms and don't know the best way to do this? My code is below. What I am effectively trying to do is give the user the ability to write a comment for their policy ref but my coding knowledge isn't very good.
<script language='JavaScript'>
function WriteToFile() {
try {
var t = document.data.comments.value;
var p = document.getElementById('policynum').innerHTML;
var msg = p + " | " + t;
var fso, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
s = fso.OpenTextFile("C:\\Test\\Logfile.txt", 8, true);
s.writeline(msg);
s.Close();
alert("Comment Saved!");
}
catch (err) {
var strErr = 'Error:';
strErr += '\nNumber:' + err.number;
strErr += '\nDescription:' + err.description;
document.write(strErr);
}
}
MY HTML form is below but in reality I will have a list of policy references where the user can enter their comments and the comment will be saved to the text file with the relating policy ref.
<form action="test.hta" method="post" name="data">
<tr align = left><td align = center id = "policynum">A12345678A01</td>
<td align = center id = td1>Testing</td><td align = center id = td1>
<textarea name="comments">this is my comment </textarea><br>
<input type=button value="Save Comment" OnClick="WriteToFile(this.form)">
</form>
<form action="test.hta" method="post" name="data">
<tr align = left><td align = center id = "policynum">A12345678A02</td>
<td align = center id = td1>Testing</td><td align = center id = td1>
<textarea name="comments">this is my comment </textarea><br>
<input type=button value="Save Comment" OnClick="WriteToFile(this.form)">
</form>
I think I will need to add something so that when OnClick function it relates to the correct form also I think I will need to make sure each form name is different?