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 392,094 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 3,888 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: 2958 | Replies: 1
Reply
Join Date: Oct 2007
Posts: 8
Reputation: Dennis_Phils is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Dennis_Phils Dennis_Phils is offline Offline
Newbie Poster

Question onkeypress does not work in Firefox when pressing enter

  #1  
Nov 28th, 2007
Hi All,

I'm having problem with the onkeypress attribute, I'm not sure if my code is right. When pressing the enter button, the javascript function would work on IE but not in Firefox. I'm not sure if the event keyCode is being recognized by Firefox or if I'm missing something...

Here's a code snippet of my code:

<td width="270px"><input type="text" id="searchB" value="" style ="font-family:Verdana; font-size:10pt; width: 270px; height:100% ;" onkeypress="enterHere();" onFocus="this.select();" ></td>


<script language="javascript" type="text/javascript">
function enterHere()
{
if((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
{
find();
}
}
</script>


Can anyone help me on this...????

Thanks...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,775
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 330
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: onkeypress does not work in Firefox when pressing enter

  #2  
Nov 28th, 2007
>When pressing the enter button, the javascript function would work on IE but not in Firefox.
This is because, in Firefox, the event is passed as a parameter to the event handler. event property of the window object is IE only.
  1. function enterHere(e)
  2. {
  3. e = e || window.event;
  4. var code = e.keyCode || e.which;
  5. if(code == 13)
  6. find();
  7. }
Last edited by ~s.o.s~ : Nov 28th, 2007 at 11:49 am.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Reply

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

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

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