473,418 Members | 1,993 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

event.keyCode=9 tab event doesn't work in FireFox

I am having trouble in calling tab event using my own function.
i call tab event using
event.keyCode = 9;
but firefox gives this error "Error: event is not defined".

What to do? plz help
May 17 '07 #1
10 35554
mrhoo
428 256MB
To script event handling beyond IE you need to learn the DOM event model.
google it, or start here-
http://www.javascriptkit.com/domref/domevent.shtml
May 17 '07 #2
in firefox you can try this:
[HTML]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/javascript">
function codeNum(e)
{
alert(e.keyCode);
}
</script>
</head>

<body>
<input type="text" onkeydown="codeNum(event)"/>
</body>
</html>

[/HTML]
May 17 '07 #3
iam_clint
1,208 Expert 1GB
actually in firefox guys its charCode not keyCode... keyCode is IE specific.
May 17 '07 #4
pbmods
5,821 Expert 4TB
First things, first, IE handles events differently from other browsers. In IE, 'event' works because Internet Explorer attaches the last event to the window. So when you type:

Expand|Select|Wrap|Line Numbers
  1. alert(event.keyCode);
  2.  
You're actually doing this (because 'with window' is assumed in JavaScript):
Expand|Select|Wrap|Line Numbers
  1. alert(window.event.keyCode);
  2.  
Instead, you want to use charCode:

Expand|Select|Wrap|Line Numbers
  1. function codeNum(e)
  2. {
  3.     if(!e)
  4.         e = window.event;
  5.     if(e.keyCode)
  6.         alert(e.keyCode);
  7.     else
  8.         alert(e.charCode);
  9. }
  10.  
May 17 '07 #5
problem is in firefox event.keycode=9 returns error because event.keycode is a getter property. so i can't set tab event by assigning keycode= 9. is there any setter property of event.keycode by which we can assign any keycode to it?
May 25 '07 #6
pbmods
5,821 Expert 4TB
is there any setter property of event.keycode by which we can assign any keycode to it?
Wait... you want to simulate a tab press?

Why not just use the focus method of the element you want to focus?
May 25 '07 #7
dear pbmods, my application creates field names on run time so i can't pass the next field name or can't move focus to the field by using its name.
May 25 '07 #8
iam_clint
1,208 Expert 1GB
and why not? add names to your elements.
May 25 '07 #9
and why not? add names to your elements.

IE provides "event.keyCode" BUT

Mozilla provides "event.which"

Try this guys..
Jun 12 '07 #10
IE provides "event.keyCode" BUT

Mozilla provides "event.which"

Try this guys..
In Mozilla using "event.which" works with almost all chars, but an example of one that it doesn't works is the TAB char,
if your code like this:
Expand|Select|Wrap|Line Numbers
  1. ........
  2. if(event.which){
  3.     ..........
  4. }else{
  5.     ..........
  6. }
  7. ........
  8.  
for the char TAB , i'm not sure why, "event.which" is eq 0 so it's evaluated as false!

I suggest to use "event.type", it returns the event occured...
Mar 14 '08 #11

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

Similar topics

17
by: Julia Briggs | last post by:
Are there any gotchas using if (event.keyCode==8)? I understand that to represent backspace, but it doesn't work. I am running Windows XP, using a typical keyboard - but no luck in detecting...
1
by: Perttu Pulkkinen | last post by:
I have different functions that receive window.event as parameter. Functions are used like this: <input type="text" id="x" onkeypress="return onKeyCurrencyCheck(ev, 'x')" onblur...
6
by: Justin Beasley | last post by:
Here is an answer for those who are looking for a keystroke evaluation script that works in Internet Explorer (IE 5.5, 6.0, 7.0 for PC--IE 4.0, 5.2 for Mac), Mozilla Firefox (Windows, Linux, and...
6
by: rich_poppleton | last post by:
Help.... I've got a textarea where people type in a description. However for certain reasons we need to stop them typing !$*^ . I have a solution this which works fine in IE: function...
3
by: niconedz | last post by:
Hi The following code works fine in IE but not Firefox. It's a little script that zooms an image and resizes the window to fit. Can anybody tell me what's wrong? Thanks Nico == btw.....
4
by: bbp | last post by:
Hello, In an ASPX page I have a "Quit" button which make a simple redirect in code-behind. This button doesn't work no more since (I think) I moved from the framework 1.0 to 1.1 and it doesn't...
7
by: CharlesA | last post by:
Hi folks, first off, I'm using .Net framework 1.1 with ASP.net and C# I'm trying to do something very simple...but I can't figure it out I have an <asp:button runat="server"> in the test...
1
by: mathewda | last post by:
Hey, I'm having a problem that I consider kinda weird that is alluding me at the moment. I've wrote some code that will set up an XMLHttpRequest, it then makes a call to open and send and sets the...
2
bilibytes
by: bilibytes | last post by:
Hi, i have been creating an ajax aplication on my website and it worked as i expected it to work on Safari and Firefox, until i upgraded to Firefox 3. It doesn't work either on windows. the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
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...

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.