[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Detecting RightClick->Delete in TextArea

Posted on 2009-12-26
2
Medium Priority
?
481 Views
Last Modified: 2013-11-05
I've got a textarea with a counter showing how many characters are left before you can't type anymore, and functionality truncating to a maximum size if you exceed it.

I've implemented this using onkeyup and onpaste (oninput in Opera, I'm aware of that difference), as well as oncut.

This traps everything except rightclick->delete.  How can I trigger an event based on that so I can toss the same functions at that event?

Please do not suggest jquery or other toolkits/frameworks, it's not going to happen.  I need raw javascript and HTML.

Thanks!
0
Comment
Question by:Fairlight2cx
2 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 26125911
Hello Fairlight2cx,

Try this :

If you past more than two chars, an alert box appear
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
	function rightClick(e) {
		ta = document.getElementById("ta");
		if(ta.value.length>2) {
			alert("More than two char");
			ta.value = ""; 
		}
	}
</script>
</head>
<body >
<textarea id="ta" cols="128" rows="16" onmousemove="rightClick()"></textarea>
</body>
</html>

Open in new window

0
 
LVL 7

Accepted Solution

by:
Fairlight2cx earned 0 total points
ID: 26126315
Well, that's not very complete.  It also actually assumes that it should trigger the detection event as soon as you mouse over the textarea, which is just a plain fallacy in and of itself...you'd miss most pastes because it would have checked before you could hit paste from the context menu.

I settled on a different solution, since I couldn't find an event to handle Delete.  I trigger via oncut/onpaste/oninput/onkeyup, and also have a 250ms setTimeout to check for length changes even when there are no events...which also has the side effect of letting you get status updates while someone is holding down a key with auto-repeat.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question