Web Analytics Made Easy -
StatCounter Trap Right Click over Textbox or TextArea - CodingForum

Announcement

Collapse
No announcement yet.

Trap Right Click over Textbox or TextArea

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trap Right Click over Textbox or TextArea

    Does anyone know how to trap a Right Click over a TextBox or TextArea

    Or at least on Right Click check if the mouse if over a TextBox or TextArea?

    I want to customise my context menu to include three functions if the mouse is over a TextArea or TextBox; namely - UpperCase, LowerCase and ProperCase

    Are there any other objects I should include in that?

    Any help or advise will be gratefully received

    Cheers Al

  • #2
    Use onmousedown event, it allows you to detect the button pressed

    Comment


    • #3
      Ravenn,

      Thanks for your reply

      I only want to display the 3 functions if the right mouse button was clicked over a textBox or text area.

      I have no problem checking for rightclick onmousedown, but rather checking whether the mouse is currently over a textbox or textarea?

      Cheers Al

      Comment


      • #4
        Use window.event.target (IE) or e.target (all other)
        Code:
        document.onclick = getTarget;
        function getTarget(e) {
        	if(typeof e == 'undefined') e = window.event;
        	if(typeof e.target == 'undefined') e.target = e.srcElement;
        	alert(e.target.nodeName);
        }
        dumpfi
        "Failure is not an option. It comes bundled with the software."
        ....../)/)..(\__/).(\(\................../)_/)......
        .....(-.-).(='.'=).(-.-)................(o.O)...../<)
        ....(.).(.)("}_("}(.)(.)...............(.)_(.))¯/.
        ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
        Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

        Comment


        • #5
          Ravenn,

          I think I've got it, something like (note: I've not included all the context menu code)



          Code:
          [color="#0000A0"]function[/color] dopopup(x,y) {
          	if(isie) {
          		var oPopupBody = oPopup.document.body;
          		oPopupBody.innerHTML = html;
          		oPopup.show(x, y, 140, 220, document.body);
          	}
          }
          
          [color="#0000A0"]function[/color] click(e) {
          	if(isie) {
          		if(document.all) {
          			if(event.button==2 || event.button==3) {
          				var el=window.event? event.srcElement: e.target
          				[color="#0000A0"]If[/color] (el.tagName=="INPUT" && el.type=="text") || (el.tagName=="TEXTAREA")) {
          					// prefix functions  
          					html = appendFunctions + html
          					dopopup(event.x-1,event.y-1);
          				}
          			}
          		}
          	}
          }
          
          if(isie) {
          	document.oncontextmenu = function() { dopopup(event.x,event.y);return false; }
          	document.onmousedown = click;
          }
          Thanks for the pointer

          Cheers Al

          Comment


          • #6
            Dumpfi,

            Thanks for the function I will test it out tomorrow, I was busy posting my reply when you posted, so didn't see it till after

            Cheers Al

            Comment

            Working...
            X