By Renee De Bock

2019-06-12 07:14:24 8 Comments

I have a textarea in my html like this:

<textarea id="area1"></textarea>

When visitors copy/paste or type something in this area i want it to save to a txt file without the visitor having to click any button.

Looked all over the web but can't find any solution.


@Chaska 2019-06-12 07:39:12

This example show how to save content automatically 2s after changing. It can prevent from doing save for every character typed.

var t;
function save() {
  t = setTimeout(function() {
    console.log('All changes saved'); // save here
  }, 2000);
<textarea onchange="save();" onkeyup="save();"></textarea>

@Renee De Bock 2019-06-12 09:33:58

does not work for me... maybe i have to try php

@Chaska 2019-06-12 09:40:10

Of course you need a php to save your content, javascript is just for passing parameters to your php

@Renee De Bock 2019-06-12 09:41:37

Well i looked all over but can not find any script example... i am not good at scripting so was kinda looking for a live or working example.

@Renee De Bock 2019-06-12 10:02:38

So far i got this... how do i call the php script?

@Chaska 2019-06-12 10:26:42

Search for jQuery and Ajax

@Guga Nemsitsveridze 2019-06-12 07:18:09

write JS function, that saves info in .txt file. Let's say, function name is saveToTxt(). Then trigger that function onChange:

<textarea id="area1" onChange="saveToTxt(this);"></textarea>


Assume that, saveToTxt() is something like that:

function saveToTxt(fld) {
    const textAreaValue = fld.value;
    // then use textArea variable as container of textarea-content
    // and then treat it as you want.

@Guga Nemsitsveridze 2019-06-12 07:22:52

@mplungjan - I edited my answer

@Guga Nemsitsveridze 2019-06-12 07:25:14

@mplungjan - You can simply edit my answer or first write it in comment section, before use downVote, isn't it right?

@Guga Nemsitsveridze 2019-06-12 07:27:29

@mplungjan - That is what I call COLLABORATION :)

@mplungjan 2019-06-12 07:27:47

oninput is still what I would use myself

@Renee De Bock 2019-06-12 09:33:37

Does not work for me... can i do this in php?

@Renee De Bock 2019-06-12 10:03:44

Or how do i call the php script to actually save the data to a txt file on the server?

Related Questions

Sponsored Content

17 Answered Questions

[SOLVED] How to disable resizable property of textarea?

  • 2011-03-08 16:15:40
  • user549757
  • 1202576 View
  • 2401 Score
  • 17 Answer
  • Tags:   html css

22 Answered Questions

[SOLVED] How can I set the default value for an HTML <select> element?

  • 2010-08-19 01:10:51
  • Jichao
  • 2189865 View
  • 1241 Score
  • 22 Answer
  • Tags:   html html-select

34 Answered Questions

29 Answered Questions

[SOLVED] How to create an HTML button that acts like a link?

31 Answered Questions

[SOLVED] How do I auto-resize an image to fit a 'div' container?

9 Answered Questions

[SOLVED] Limit file format when using <input type="file">?

  • 2010-12-01 20:44:40
  • Bojangles
  • 430436 View
  • 544 Score
  • 9 Answer
  • Tags:   html file types

30 Answered Questions

[SOLVED] How do you parse and process HTML/XML in PHP?

18 Answered Questions

[SOLVED] How do I modify the URL without reloading the page?

20 Answered Questions

[SOLVED] How to trigger a file download when clicking an HTML button or JavaScript

16 Answered Questions

Sponsored Content