User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 427,177 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,244 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 498 | Replies: 6
Reply
Join Date: Apr 2007
Posts: 257
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

javascript help

  #1  
Jul 24th, 2008
I

 
function numvalues()
{
if((window.event.keyCode>57)||(window.event.keyCode<48))
			{
			    alert("Only Digits Are Allowed");
				window.event.keyCode=null;
			}
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2007
Posts: 257
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: javascript help

  #2  
Jul 24th, 2008
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
Reply With Quote  
Join Date: Jul 2008
Location: Sweet India
Posts: 828
Reputation: Shanti Chepuru is on a distinguished road 
Rep Power: 2
Solved Threads: 74
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Practically a Posting Shark

Re: javascript help

  #3  
Jul 24th, 2008
try this:
  1. <body onKeyDown="setCmdKeyIE(event);" >
  2.  
  3. javascript:
  4.  
  5. function setCmdKeyIE(event) {
  6. if(event==null) event = window.event;
  7. var cmdkeycode = "";
  8. if (event.keyCode != 13 & event.keyCode != 33 &
  9. event.keyCode != 34 & event.keyCode < 112 ) return;
  10. ...
  11. }
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote  
Join Date: Jul 2008
Location: Sweet India
Posts: 828
Reputation: Shanti Chepuru is on a distinguished road 
Rep Power: 2
Solved Threads: 74
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Practically a Posting Shark

Re: javascript help

  #4  
Jul 24th, 2008
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.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote  
Join Date: Apr 2007
Posts: 257
Reputation: greeny_1984 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz in Training

Re: javascript help

  #5  
Jul 24th, 2008
"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.
Reply With Quote  
Join Date: Jul 2008
Location: Sweet India
Posts: 828
Reputation: Shanti Chepuru is on a distinguished road 
Rep Power: 2
Solved Threads: 74
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Practically a Posting Shark

Re: javascript help

  #6  
Jul 24th, 2008
i dont know about asp.net
sorry.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote  
Join Date: Jun 2008
Posts: 74
Reputation: Troy III is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 11
Troy III's Avatar
Troy III Troy III is offline Offline
Junior Poster in Training

Re: javascript help

  #7  
Jul 24th, 2008
Originally Posted by greeny_1984 View Post
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 9:37 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC