0

I

function numvalues()
{
if((window.event.keyCode>57)||(window.event.keyCode<48))
			{
			    alert("Only Digits Are Allowed");
				window.event.keyCode=null;
			}
}
3
Contributors
6
Replies
7
Views
9 Years
Discussion Span
Last Post by Troy III
0

I HAVE A FUNCTION AS SHOWN ABOVE,IT IS WORKING FINE IN IE but it is not working in firefox,can any one suggest wats wrong

0

try this:

<body onKeyDown="setCmdKeyIE(event);" >

JAVASCRIPT:

function setCmdKeyIE(event) {
  if(event==null) event =  window.event;
   var cmdkeycode = "";
   if (event.keyCode != 13 & event.keyCode != 33 &
      event.keyCode != 34 & event.keyCode < 112 ) return;
   ...
}
0

Firefox doesn't use the global window.event but the passes an event
object to the handler. However if you use just "event" it will work as
this will be the event object within your handler.

onkeypress="return onKeyCurrencyCheck(event, 'x')"

keyCode is also know by firefox, but if you use keypress you may check
for charCode.

0

"Firefox doesn't use the global window.event but the passes an event
object to the handler. However if you use just "event" it will work as
this will be the event object within your handler."
can u elaborate this,
u mean to say mozilla doesnt require window.event,so in order to use that function we have to send event as a paramater.

iam a asp.net developer
iam using control
<asp:textbox >
when sending event as a paramter to the function,it is returning undefined for event.

0

I

function numvalues()
{
if((window.event.keyCode>57)||(window.event.keyCode<48))
			{
			    alert("Only Digits Are Allowed");
				window.event.keyCode=null;
			}
}

Take this:

function numvalues(e){
	if(!e) e=event;e=e.keyCode||e.which;//b.b. TroyIII p.a.e
	if((e>57)||(e<48)) {alert("Only Digits Are Allowed!"); return false;}
	}
document.onkeypress=numvalues

You should use yourElement.onkeypress=numvalues instead!

p.s.: I'm not sure what were you thinking with the window.event.keyCode=null; , but I assumed you wan'ed to dissable it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.