Paste data into several textboxes simultaneously

Talk about add-ons and extension development.
Post Reply
ZguRRo
Posts: 3
Joined: August 7th, 2015, 6:08 am

Paste data into several textboxes simultaneously

Post by ZguRRo »

Hello everybody!

I created an add-on which manipulates clipboard and pastes certain text into any textbox on the webpage.
On this webpage I have several textboxes with the same ID.

Now I need to paste text into all these textboxes simultaneously. For example, if I paste something into the
first (or any other) textbox it will be automatically pasted into all other textboxes.

I didn't find any examples or experiences with that in the internet. So, I will be happy to any suggestions/solutions.

Thanks!
Noitidart
Posts: 1168
Joined: September 16th, 2007, 8:01 am

Re: Paste data into several textboxes simultaneously

Post by Noitidart »

What is the code you are using for pasting?

You can get the contents from the clipboard and set the value of the textboxes to it: http://stackoverflow.com/questions/2654 ... 9#26554409
User avatar
Shadoefax
Posts: 465
Joined: April 29th, 2005, 2:59 pm
Location: Glendale, AZ
Contact:

Re: Paste data into several textboxes simultaneously

Post by Shadoefax »

It's generally not a good idea to use the same id on different tags. For instance, what would be returned in this statement:

Code: Select all

var node = document.getElementById("non-unique_id")


I'm not sure, but I would imagine you'd only get a reference to the first tag with that id.
All my signatures are stolen from other people. Including this one.
Homepage
lithopsian
Posts: 3664
Joined: September 15th, 2010, 9:03 am

Re: Paste data into several textboxes simultaneously

Post by lithopsian »

A group of logically-related elements would typically be identified using a class. They can be selected, as an HTMLCollection, using getElementsByClassName(). It isn't the only way, but certainly using the same ID attribute on multiple elements is not the way to go. You can potentially group them using any attribute you like, but the generalised querySelector() you would use to find them all is nowhere near as simple to use as getElementsByClassName().
Post Reply