Skip to main content
Participant
May 4, 2018
Question

Javascript saves form output locally

  • May 4, 2018
  • 1 reply
  • 448 views

Hi

Im looking for some help in creating an HTML form. Using DW CC 2018 I have made a very simple form with 5 checkboxes. I want to  save the output when submitted to a text file, ideally using a filename generated from the date. Can this be done without creating a php file. I don't want it stored on a server it is being entered and hopefully saved on a standalone PC. Any help would be appreciated, I'm OK with HTML and a beginner with JS (which I think is the way to do it)

This topic has been closed for replies.

1 reply

Legend
May 4, 2018

This is the Acrobat JavaScript forum, which has no connection to web browser JavaScript. Surely web browsers cannot save text files locally, though, that would be a horrendous security hole. When you submit it goes to a web browser (PHP, ASP, CGI etc.) written by an experienced web professional up to date with the latest security threats and tricks. Submit only means that, not a local action.

Participant
May 4, 2018

Sorry - as stated I am a beginner.

Security is not really an issue as its a standalone PC (otherwise i would use PHP or ASP)

I was using this as a basis which works but I want to add more fields and if possible use a function to automatically name the file based on the date.....

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

    <style>

form * {

  display: block;

  margin: 10px;

}

</style>

    <script language="Javascript">

function download(filename, text) {

  var pom = document.createElement('a');

  pom.setAttribute('href', 'data:text/plain;charset=utf-8,' +

encodeURIComponent(text));

  pom.setAttribute('download', filename);

  pom.style.display = 'none';

  document.body.appendChild(pom);

  pom.click();

  document.body.removeChild(pom);

}

</script>

    <title>Form_Test_Local</title>

  </head>

  <body>

    <form onsubmit="download(this['name'].value, this['text'].value)"> <input

        name="name" value="test.txt" type="text"> <textarea rows="3" cols="50" name="text">Please type in this box. When you

click the Download button, the contents of this box will be downloaded to

your machine at the location you specify. Pretty nifty. </textarea> <input value="Download" type="submit">

    </form>

  </body>

</html>