0

I'm making a form on JavaScript and I want to save all of the users entered variables to either a .txt file or a new webpage with the variables pre entered in the inputs. I understand the JavaScript cant manipulate the users machine but can it manipulate the servers files(create new files) If it can how would one save variables onto a new file in a way that could then be imported back into the website? Any input is appreciated :) Aaron~

2 Answers 2

1

JavaScript running in the browser can make HTTP requests to the server (generally by using the XMLHTTPRequest object).

It can't write arbitrary files to it (if it could, then any client could, and anyone could deface any website)

You need some form of server side process running on the server that can interpret an HTTP request as meaning "Write something to a file" (although, in most cases, you would write to a database and generate the file on request from the data there).

You could write the server side process in JavaScript if you have a suitable server side environment (such as Node.js).

Sign up to request clarification or add additional context in comments.

5 Comments

So are you saying I should learn how to write mySQL or something? is there any API that might help me do this?
MySQL is serviceable. There are MySQL APIs for most programming languages, including JavaScript in a Node.js environment.
Now gonna research the Node.js (i'm kinda new to js :P) any tips for it? Thank you as well :)
I wouldn't rush to Node.js unless you really, really wanted to use JavaScript or needed crazy performance. It's still fairly new (although plenty of people are using it successfully). I'd start by seeing what your existing hosting offered.
This site is for my college coursework. and one of the features needed is that the site saves the users variable into a log file. I kinda need to rush into it :s
0

It's not possible. JS is restricted by client side. if you like to store form data, you have to have server side engine which will handle POST request of your form data and save wherever you like: database & files & etc

Comments

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.