lundi 30 mars 2015

Reading and writing a form to a text file without PHP

I have an html form with questions on it, then there’s a check box, then there’s an area for comments, so it looks something like this…



<TR>
<TD><p id=txt1 > Have you created the account? p></TD>
<TD><INPUT id=chk1 type=checkbox value= YES name=Q1><BR>
<TD><INPUT id=com1 size=40 name=comments></TD></TR>
<TR>


It started as a small form with a handful of questions, now it’s a huge form with a growing bank of questions. I’m using a javascript function to s.wirte the formdata to a text file… (I have no server so can’t use PHP or any server side functions,this all needs to happen on the client PC, the activex notices are not a problem for me, this is only used by IT staff)


Example…



function WriteToFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\\Answers.txt", true);
s.Write(document.getElementById("txt1").innerText);
s.Write(" ");
s.Write(document.getElementById("chk1").checked);
s.Write(" ");
s.WriteLine(document.getElementById("com1").value);


The HTML form is now huge; I was hoping to find a more simple method of coding this form using a loop and an array to read the bank of questions from one text file “questions.txt” and another loop to Display the questions in a Table and then at the click of a button writing the questions and answers back to another text file “answers.txt”


so that the question bank could be easily expanded without rewriting the HTML page every time.


I’m new to JavaScript and I have attempted get this to work but I’m having no luck.


Can someone start me off with a simple sample that I could adapt?


Aucun commentaire:

Enregistrer un commentaire