I

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

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

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;
   ...
}

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.

"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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.