Connecting Tech Pros Worldwide Forums | Help | Site Map

Capturing event when User right-click->paste into text box

RBPierce's Avatar
Newbie
 
Join Date: Sep 2007
Posts: 6
#1: Sep 5 '07
Hey all, hoping someone can help me with a workaround. I've got an event set to fire when a textbox changes or loses focus- no problems. However, when the user clicks into the box and Right Click--> Pastes a value into it, I can't get any event to fire. I've tried onClick, OnChange, OnMouseDown, onMouseUp, onKeyDown, and onKeyUp.
Expand|Select|Wrap|Line Numbers
  1. <input type='text' onChange="alert('Changed')" onClick="alert('Clicked')" onMouseDown="alert('onMouseDown')" onMouseUp="alert('onMouseUp')" onKeyDown="alert('onKeyDown')" onKeyUp="alert('onKeyUp')">
I know I can do one of those stupid IE named scripts, but I was hoping someone somewhere had a multi-browser compliant solution!

http://msdn2.microsoft.com/en-us/library/ms536955.aspx

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Sep 5 '07

re: Capturing event when User right-click->paste into text box


Heya, RB. Welcome to TSDN!

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#3: Sep 5 '07

re: Capturing event when User right-click->paste into text box


Welcome to TSDN!

Unfortunately, there's no reliable cross-browser way to capture a paste event. You can check this thread out. Why is it so important to capture this? Can you not just wait for onchange to fire when the text box loses focus?
RBPierce's Avatar
Newbie
 
Join Date: Sep 2007
Posts: 6
#4: Sep 5 '07

re: Capturing event when User right-click->paste into text box


Thanks PB!

acoder, upon successfully completing the input field in question, that value is then used to auto-complete various other fields on the page. If the user has to wait until they have tabbed/clicked to another input box in order for the auto-completion to kick in, we have violated GUI best practices by separating cause and effect.

Additionally, I have helper text in which prompts the user what is needed, i.e. "Start Date required". That text disappears after a valid date is entered... unless they mouse paste, in which case the text remains, while they can clearly see that a good date WAS entered.

Anyway, thanks for the help!
iam_clint's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#5: Sep 5 '07

re: Capturing event when User right-click->paste into text box


you can write a timer to check the value of the so called input box

Example provided.
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. var ival = "";
  3. var checkup = window.setInterval("checkChange();", 100);
  4. function checkChange() {
  5. var nval = document.getElementById("test").value;
  6. if (nval!=ival) { alert("change in the text"); ival=nval; }
  7. }
  8. </script>
  9. <input type="text" id="test" name="test" value="">
  10.  
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Sep 6 '07

re: Capturing event when User right-click->paste into text box


Quote:

Originally Posted by RBPierce

acoder, upon successfully completing the input field in question, that value is then used to auto-complete various other fields on the page. If the user has to wait until they have tabbed/clicked to another input box in order for the auto-completion to kick in, we have violated GUI best practices by separating cause and effect.

Additionally, I have helper text in which prompts the user what is needed, i.e. "Start Date required". That text disappears after a valid date is entered... unless they mouse paste, in which case the text remains, while they can clearly see that a good date WAS entered.

Aah, that makes more sense. Well, iam_clint has posted a good workaround. Hopefully that should solve your problem.
RBPierce's Avatar
Newbie
 
Join Date: Sep 2007
Posts: 6
#7: Sep 6 '07

re: Capturing event when User right-click->paste into text box


Thanks iam- I'll look into it!
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#8: Sep 6 '07

re: Capturing event when User right-click->paste into text box


I wonder if you can use an onclick or maybe onrightclick (?) event handler that compares the current value of the textbox to the last value....

[EDIT: Just about the same thing iam_clint posted, except without the setInterval() call. Ah well.]
Reply