1

This is a javascript code which saves a textarea onto a text file. This fiddle does the same.:
https://jsfiddle.net/pzvvhfv6/

I needed to add this feature in my code, so modified it so that onclick of the button, the text area is saved and a new file is created. But, for some strange reason, it shows uncaught reference error onclick. Below is the code Im working on.
https://jsfiddle.net/vu7thh34/

function call(){
   var create = document.getElementById('create');
    var textbox = document.getElementById('textbox');
    var link = document.getElementById('downloadlink');
    link.href = makeTextFile(textbox.value);
    link.style.display = 'block';
  }

HTML:

<textarea id="textbox">Type something here</textarea>  <button id="create">Create file</button> <a download="info.txt" id="downloadlink" style="display: none">Download</a>

Is there any problem with the code?

chintu
  • 11
  • 3

1 Answers1

1

JSFiddle does not recognize inline handlers that reference functions in the lower JavaScript section.

Inline handlers are bad practice anyway - they're essentially eval inside HTML markup. Attach the listener properly using Javascript instead, and JSFiddle won't have any problem with it:

document.querySelector('#create').onclick = call;

Another option is to put your code in a <script> tag in the HTML instead of in the Javascript section of JSFiddle, but that's not a good idea.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320