user

Great Coder

11 Feb 2022

Coping plain text into form bug.

Javascript

I wrote the following code and use it to copy and submit types of data into a form.

In fact I used to use this small peace of code in the past to copy just images as the browsers abilities were limited, but now they have allowed this to all types of data including texts too.

The problem here is that the code thinks that the text is a file when copies and goes directly to submit.

How to fix that?

 

let fileInput = document.getElementById("doc_attachment");

window.addEventListener('paste', e => {
 fileInput.files = e.clipboardData.files;
 document.getElementById("new_doc_attachment").submit();
}); 

Comments

nico

19 Feb 2022

Hello did you try the following to get the data ?

 

event.clipboardData.getData("text")

© 2024 Copyrights reserved for web-brackets.com