aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes onpaste event in a drop down list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "onpaste event in a drop down list" Watch "onpaste event in a drop down list" New topic
Author

onpaste event in a drop down list

Marco Antonio
Ranch Hand

Joined: Apr 23, 2008
Posts: 74
Hi everybody!

In IE9 I need to capture the paste event in a drop down list through JavaScript, but I hadn't positive results. I can capture the even in a text field or a textarea one, but with a drop down list it has been impossible. Neither the Ctrl+v nor the Paste option on context menu have been captured. I've tried to use the HTML [<ELEMENT onpaste="handler">] and the JavaScript [object.addEventListener ("paste", handler, useCapture);] ways to declare the handler with the same result.

What I'm trying to do is capture that event, parse the pasted text (in a specific format) and generate the suitable options elements according with the pasted text.

I wonder if you could say me how to capture that event for a drop down list, if it is possible.


Thank you in advance for all your answers.


Any correction of my English will be gratefully accepted.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

Where would you paste into a drop down? A drop down is a select tag which doesn't allow you to enter data only select what is there. Or are we talking about some other construct?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Marco Antonio
Ranch Hand

Joined: Apr 23, 2008
Posts: 74
Hi!

First of all, thank you for you interest.

About my question, I don't matter where the user paste the mentioned formated text, whether the drop down list is collapsed or expanded. What I need is capture the paste event in a drop down list.

I have been looking for documentation about this, and the <select> element accept that event.

http://help.dottoro.com/ljuimtmq.php#supByObj

or

http://msdn.microsoft.com/en-us/library/ie/ms535893(v=vs.85).aspx#events

However, the event is not captured when I paste something neither the Ctrl+v shortcut nor the Paste option on context menu. I have tried to paste the text with the drop down list collapsed, expanded, with options, empty, with multiple selection, with single one, etc.

If the <select> element accept the event, why cannot it be captured? Is it definitely impossible? In this case, why does it accept the event? In what cases it can be used?


Thank you so much.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

Interesting. The w3c says the paste event triggers even on a non-editable element. I agree that doesn't appear to be happening though.

I was thinking to suggest you use a transparent div. However, this example with a div works for me in Chrome and not Safari.

I'm still not clear on what you are trying to accomplish though. Why would a user logically try to paste over a select list?
Marco Antonio
Ranch Hand

Joined: Apr 23, 2008
Posts: 74
Thank you, Jeanne.

Yes, it is interesting that a non editable element can capture the paste event, and it is more interesting why the browser implementation doesn't follow the specification (well, perhaps because it is a draft).

Anyway, I've convinced myselft that the event paste is not capture by a drop down list, at this moment. Perhaps, in the future, when the specification is released.....

About you question over the reason of being trying to capture the event, it is because my customer wants to be able to paste a formatted list over a drop down list, and this action must provoke that the elements of the pasted list are options of the drop down list element. I cannot use a div over the element because the options must can be selected. At this moment, I'll have to use another element (text field, text area) to capture the paste event with the formatted list and accomplish the required functionality.

Well, thank you again for your interest


Best regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: onpaste event in a drop down list