Skip to content
Advertisement

How to copy multiple text input to clipboard

I have already learned how to copy a single text input to the clipboard. However I can’t seem to figure out how to copy multiple text inputs to the clipboard. Can someone please help me figure this out for my project. Cheers!

JavaScript

Advertisement

Answer

As CBroe already wrote, you overwrite your buffer with every further copying process and thus only the last entry remains. One possibility would be to create a new field for a short time and to store the content of all elements there and then to copy it to the buffer. It could look something like this:

JavaScript

Of course, this is not a complete code. For example, there is no error handling if a field was not found. But it shows how it could work.

Update

Another method would be to use the current browser api. This is only possible with modern browsers. But be careful, this method is asynchronous. Can I use navigator.clipboard?

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement