473,500 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onKeyPress() not working in mozilla. PLease Help.

65 New Member
Hi,

I have a textbox which takes in values and besides it there is a submit button. Currently on click of the submit button calls a java script function and redirects to a page.

So currently after entering the values on hitting the enter on the keyboard does not call the JS Function.

So how can i went on to implement this where on hitting enter it calls my JS function:

JavaScript Function:
function txtKeywordKeyPress() {


if (window.event.keyCode == 13)
{
var keyWord = trimAll(document.getElementById('satitleTextBox'). value);
if(keyWord.length > 0)
{
Search_Click();
return true;
}
}


}

html code:

<input type="text" onkeypress="txtKeywordKeyPress()" size="40" maxlength="300" id="satitleTextBox">

Its worknig fine in IE but not in Mozilla..

PLease help..
Apr 10 '07 #1
3 5960
mrhoo
428 Contributor
It's not just firefox.
Most browsers outside of IE do not have a global window.event.
They pass the event on to the individual event handler-


Expand|Select|Wrap|Line Numbers
  1. function txtKeywordKeyPress(e){
  2.     e= e || window.event;
  3.     if (e.keyCode == 13){
  4.         var keyWord = trimAll(document.getElementById('satitleTextBox'). value);
  5.         if(keyWord.length > 0){
  6.             Search_Click();
  7.             return true;
  8.         }
  9.     }
  10. }
Apr 10 '07 #2
Nitinkcv
65 New Member
Hi,

So how should i call my script function, something like:

<input type="text".... onkeypress="txtKeywordKeyPress(e)" />

Thanks,
Nitin
Apr 10 '07 #3
mrhoo
428 Contributor
To call it from inline html, use 'event'-
<input type="text".... onkeypress="txtKeywordKeyPress(event)" />

But better is to separate javascript from html.
In a script you can set inputelement.onkeypress=txtKeywordKeyPress;
and pass the event automatically.
Apr 10 '07 #4

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

Similar topics

5
9752
by: Fred Brown | last post by:
Hi, I want to cancel a certain key in JavaScript. To do so, I catch the event in OnKeyPress and cancel the default: <head> .... function f(evt) { var evt = (evt) ? evt : ((window.event) ?...
5
4173
by: Albert Wagner | last post by:
I have included a file below that tests onKeyPress in Opera 7.11. I am getting peculiar behavior. When the file is first loaded, pressing the keypad + causes the textarea to get physically larger...
7
4079
by: Kev | last post by:
I need to make some specific alterations to some JavaScript in webpages in order to comply with government guidelines on accessibility. Apparently, whenever the OnClick event is used, it must be...
4
1906
by: Jonas | last post by:
Hi! I have a web page where I want to intercept keypress events in an INPUT-tag and check if it is the Enter key, which calls another function that executes a search. My code runs on Netscape 7...
11
31048
by: LilAndy23 | last post by:
How can I use the onKeyPress event handler in Firefox? onKeyPress doesn't seem to fire in Firefox.
2
3304
by: Marc Robitaille | last post by:
Hello, I think it is a easy question but I don't have any clue how to do it...Is it possible to replace the char that a user type in a textbox with an other one in the OnKeyPress methode? My...
3
9990
by: Juan | last post by:
Hello: I'm having a problem with a simple javascript code that checks if the enter key had been pressed or not. The code works propertly in mozilla, but in iexplorer it only works one time, the...
6
1712
pravinda
by: pravinda | last post by:
Hi, I got a problem please check http://www.technocreative.com/ both in the iexplore and mozilla(firefox). it is working well in explore but problem in mozilla i am get big problem so please do...
6
2019
rrocket
by: rrocket | last post by:
Anyone know how to get onkeypress to work with keycode? I need to figure out what the keycode is before the character shows up in a textbox. Here is the code I have so far (see below). I can get...
0
7018
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...
0
7232
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...
1
6906
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...
0
7397
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...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
316
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...

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.