-1
<button type="submit" class="myButton" onclick="window.open('test.txt')">Money Dispenser</button>

Is the current code i have, and does not do anything at all when i click it. ( I want it to download test.txt to the computer or device of the user who cliked it)

SycoBak
  • 1
  • 1
  • 4
  • Does this answer your question? [DIV onClick event force download a pdf file](https://stackoverflow.com/questions/18505692/div-onclick-event-force-download-a-pdf-file) – DCCoder Oct 15 '20 at 14:24

3 Answers3

0

You can do using:

<a href="data:text/plain;charset=UTF-8,test.txt" download>Download</a>
0

I don't really understand what you are trying to achieve using a submit button, if it's not mandatory I'd use an <a>.

With pure HTML5 using the download attribute

<a href="test.txt" download>Money Dispenser</a>

Or with Javascript if you have to use a <button>

This has already been covered grealy in this question

But the gist of it is, create a function to download files as shown on that thread and add it to your <button>

<button onclick="donwloaURI('data:text/plain,Test', 'Test.txt')">Money Dispenser</button>
0

You can use the HTML download attribute to specify that the target will be downloaded when a user clicks on the hyperlink.

<a href="/download-file-path-here" download>
  Money Dispenser
</a>
Rafee Shaik
  • 681
  • 4
  • 10