473,659 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript Firefox Cancel Form Submission by Enter Key

1 New Member
Hello All

I am trying to duplicate this code which works in IE to work in Firefox

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="javascript">
  2. function submitOnEnterKey()
  3. {    if(event.keyCode == 13) {
  4.       event.returnValue = false;
  5.     } else {
  6.       event.cancelBubble = true    
  7.     }    
  8.  
  9.     if(event.keyCode == 13) 
  10.     {    
  11.       SearchUser();
  12.     } 
  13. </SCRIPT>
  14.  
Any Suggestions or hopefully solutions

I've been to http://www.quirksmode.org/dom/ and other places but can't quite find the definitive solution.

Again I am trying to cancel the default action of submitting a form with the enter key.

Thanks in advance
Adam
Apr 13 '06 #1
3 9110
acoder
16,027 Recognized Expert Moderator MVP
Only IE uses the global window.event, other browsers use the passed event.

cancelBubble only works in IE. Use the stopPropagation () method for other browsers, but not needed here. Also, check for 'which' in addition to keyCode:
Expand|Select|Wrap|Line Numbers
  1. function cancelSubmitOnEnterKey(e)
  2. {
  3.     if (!e) e = window.event;
  4.     if (e.keyCode) code = e.keyCode;
  5.     else if (e.which) code = e.which;
  6.     if (code == 13) {
  7.       SearchUser();
  8.       return false;
  9.     } else {
  10.       return true;
  11.     }
  12. }
You may also want to check that the element is not a textarea.
Apr 9 '08 #2
kunal pawar
297 Contributor
this may helps you

Expand|Select|Wrap|Line Numbers
  1. function keyPressHandler()
  2.         {
  3.             var kC  = (window.event) ?    // MSIE or Firefox?
  4.                      event.keyCode : e.keyCode;
  5.             var Ent = (window.event) ?   
  6.                     13 : e.DOM_VK_ESCAPE // MSIE : Firefox
  7.  
  8.             if(kC==Esc){return false;}
  9.         }
Apr 11 '08 #3
gits
5,390 Recognized Expert Moderator Expert
hi ...

please be sure next time that you make use of the [code] tags according to the posting guidelines when posting source code ...

regards
MOD
Apr 11 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
4883
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes because then it didn't work in IE. How can I enable this javascipt form validation to work in Netscape? When I use netscape, none of the alert boxes appear. It submits the form without validating anything.
5
2675
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one function to verify the name fields, age, email and gender. My question is: if I create a function for each field like the code below, what would be the best way to organize the functions and call them? Would I need one main function and place...
1
3786
by: Zaidan | last post by:
I am running Excel2000 under WIN98 2nd edition, and I am writing a VBA code (I will consider using javascript if I have to) that does the following, at the user command: 1- Start MS Explorer and go to my website. Login (enter ID and Password) 2- It will go and update some prices of some products that I sell 3- It will add new products or cancel some product I already have someone who wrote me in JavaScript a web form (no documentation...
8
3020
by: Prometheus Research | last post by:
http://newyork.craigslist.org/eng/34043771.html We need a JavaScript component which will auto-submit a form after a set period has elapsed. The component must display a counter that dynamically shows the minutes and seconds remaining before submission. We have a fairly tight deadline (by 5PM EST, Friday, June 25); we are using a "bounty" in the hope of getting a few good responses in a hurry. BOUNTY: $200 for first place, plus a $50...
2
2215
by: Greg T | last post by:
Hi, I have a rather long form that I don't want people submitting unless they are absolutely sure they are ready. I figured the easiest way to prevent an accidental form submission by way of hitting of the enter key was to simply not have a submit button, instead going for a regular anchor which calls a javascript confirmation box and then submits the form.
14
5453
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I have been able to come. I added a little asp.net code and an asp.net button and cannot get it to
8
3657
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
27
4728
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
4
1660
by: Goofy | last post by:
Hi everyone, My question is related to making a form submit using javascript. Here is my scenario. I have a form, which includes a user control. The user control has a search button and a submit button. I have visably hidden th search button by setting its appearance and added an HTML button which calls the click event of my real server control button. This works fine.
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.