0

I need to append the data entered in a form on a webpage into a txt file called "text.txt". I'm not sure what the issue is but my knowledge of jscript is very limited.

<html>
    <head>
        <title>Form</title>
        <script> 
            function Write(Forename, Surname) 
            {
                var fso, f, r;
                var ForReading = 1, ForWriting = 8;
                fso = new ActiveXObject("Scripting.FileSystemObject");
                f = fso.OpenTextFile("text.txt", ForWriting, true);
                f.Write(Forename + Surname);
                f.Close();
            }
        </script>
    </head>
            <form onSubmit="Write(this['Forename'].value, this['Surname'].value)">
            <input type="text" name="Forename" id="Forename" value="Forename" size="20">
            <input type="text" name="Surname" id="Surname" value="Surname" size="20">

            <input type="submit" value="Add Person">
        </form>
</html>

there is a file called "text.txt" in the same folder

4
  • 1
    Does this answer your question? Is it possible to write data to file using only JavaScript? Commented May 10, 2024 at 12:19
  • What are you trying to achieve with that file? Do you want to save this file on server or on client side? "in the same folder" is very vague. Also you are using ActiveXObject which is only supported by Internet explorer. As this browser is dead, you should not rely on that. Commented May 10, 2024 at 12:26
  • @JSONDerulo, Sorry if it wasn't made clear, I'm aiming to append user-entered data to a client side txt file. I am working on this for a small client-side webpage project and everything is stored and run on the same desktop PC Commented May 10, 2024 at 12:50
  • Return false from onSubmit attribute, then this will work in IE (only), if you've allowed to create ActiveXObjects in Intranet Zone security settings. Commented May 13, 2024 at 17:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.