0

So I am currently having an issue where I have a button set up in HTML that checks which of series of check boxes are checked through a JavaScript function. Based on which of these check boxes are checked the function writes numbers (ex: 1.2,...3.4, etc) to a variable. I would like to get the contents of that variable into a text file but after some research it appears that JavaScript cannot write to a file. I was wondering if anyone has some means of getting the contents of this variable into a place where I can send it to a text file like php?

3
  • The simplest way would probably be to post the data to a page that can write to a file -- that is, a PHP or ASP/ASPX (or similar) page that runs code on the server and can access its resources. But you won't be able to create a text file on the client, if that's what you're trying to do. Commented Apr 3, 2014 at 19:56
  • Technically speaking, if the Javascript saves the data into a cookie, you're saving the file locally. :) Commented Apr 3, 2014 at 21:04
  • Javascript can write to a text file, just not not within a regular web browser. IF you are running under Windows, and you are running the file locally off your hard drive you can use HTA. See this answer for details. Commented Apr 4, 2014 at 4:57

1 Answer 1

0

Javascript is code that runs on the client. You can have the Javascript (or a form!) generate a request to the server to create a file on the server with the necessary text you want in the file. You can then request for that file from the server. The server code will have to handle all of this, whether you use Java, PHP, ASP, etc...

If you just want text from a variable, you can setup the Javascript to simply alert( variable );, or if you want to be less intrusive, display it in your Console: console.log( variable );

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

3 Comments

How do I go about generating a request to the server?
That question is too broad. All interactions on the web (except peer-to-peer) are requests to a server. You need to do more research on the web and specify more.
Okay, I'll try to look around for some info.

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.