ian said the following in news:comp.lang.javascript on 1/13/2006 at
11:35 AM:
Hi,
I am currently using a Javascript function to dissallow the enter key
on my ASP.NET (2.0) web page, as follows:
Let's be frank, up front. You are not disallowing it, you are attempting
to disallow it.
function fnTrapKP(){
if (document.all)
{
if (event.keyCode == 13)
If you use feature detection (the if(document.all) statement) then
feature detect for what you want to use.
if (event && event.keyCode && event.keyCode == 13)
{
event.returnValue=false;
event.cancelBubble = true;
}
}
}
I call this from the body of my master page as follows:
<body onkeypress="fnTrapKP();">
On one of my pages I have a multiline textbox. The function above now
stops a user from untering multiple lines of text in to this textbox.
Is there any way I can modify the function to only allow the enter key
to be allowed when my multiline textbox has the focus?
var isBlurred = true;
function fnTrapKP(){
if (event && event.keyCode && (event.keyCode==13) && isBlurred)
{return false;}
return true;
}
<body onkeypress="return fnTrapKP();">
<textarea>Enter not allowed</textarea>
<textarea onfocus="isBlurred=false;" onblur="isBlurred=true;">Enter
allowed</textarea>
--
Randy
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/