Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Javascript works in IE but not in Firefox
Old 12-16-2005, 01:58 PM Javascript works in IE but not in Firefox
Junior Talker

Posts: 1
Trades: 0
Hi there, this is my first post!

I'm having a problem with a javascript that works in IE but not in Firefox. I'm working with c# and asp.net. The script is to set the focus to a particular asp image button on the page when the user hit's the 'enter' key. here is the script:

Code:
function onkey()  {         
     if (window.event.keyCode==13) {                  
     document.getElementById("but_update").focus();         
     }     
}
And then in the form tag, I put

Code:
<form id="form1" method="post" runat="server" onkeydown="onkey();">
Now all this works in IE, but not in Firefox. Any idea why?
maguidhir is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-16-2005, 03:15 PM
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
If you look at the Javascript console for Firefox it says it's not getting the window.event.. pass the event to the function:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
		<script type="text/javascript"><!--
function onkey(e)  {      
     if (e.keyCode==13) {                  
     document.getElementById("but_update").focus();         
     }     
}
//-->
</script>
	</head>

	<body bgcolor="#ffffff">
		<form id="FormName" action="" method="get" name="FormName">
			<input type="text" name="textfieldName" size="24" onkeypress="onkey(event); return false;"><input id="but_update" type="image" name="but_update" src="" alt="" height="50" width="50">
		</form>
		<p></p>
	</body>

</html>
Does that work in IE? (I'm on a Mac)
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 12-23-2005, 07:52 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Try this instead.

Code:
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) 
		document.getElementById("but_update").focus();
Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Reply     « Reply to Javascript works in IE but not in Firefox
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11268 seconds with 12 queries