By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,480 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,480 IT Pros & Developers. It's quick & easy.

Change "tab" to "enter" button script : Works perfectly in IE, but not in Firefox

P: 1
I have a html page that has javascript that works perfectly in IE, but not in Firefox. The use of this javascript to change "Tab" to "Enter" Button. When we press Tab, it is like when we press Enter button. How to make this script can be run on Firefox?

I would be grateful to anybody who can help me on this, as I have got out of my depth with this problem.

Thanks,
Arya

======== This is the script :

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2. <!--
  3.  
  4. document.onkeydown = checkKey;
  5.  
  6. function checkKey(oEvent){
  7.  
  8.   var oEvent = (oEvent)? oEvent : window.event;
  9.   var oTarget =(oEvent.target)? oEvent.target : oEvent.srcElement;
  10.   if(oTarget.type=="text" && oEvent.keyCode==13) 
  11.     //return false;
  12.     oEvent.keyCode = 9;
  13. }
  14.  
  15. // -->
  16. </script>
  17.  
  18. <form name="form1" method="post" action="">
  19.   <table width="200" border="1">
  20.     <tr>
  21.       <td>aaaaa</td>
  22.       <td><input type="text" name="textfield" tabindex="1"></td>
  23.     </tr>
  24.     <tr>
  25.       <td>bbbb</td>
  26.       <td><input type="text" name="textfield" tabindex="2"></td>
  27.     </tr>
  28.     <tr>
  29.       <td>ccccc</td>
  30.       <td><input type="text" name="textfield" tabindex="3"></td>
  31.     </tr>
  32.     <tr>
  33.       <td>dddd</td>
  34.       <td><input type="text" name="textfield" tabindex="4"></td>
  35.     </tr>
  36.     <tr>
  37.       <td colspan="2"><input type="submit" name="Submit" value="Submit" tabindex="5"></td>
  38.     </tr>
  39.   </table>
  40. </form>
Aug 30 '06 #1

✓ answered by Logician

. The use of this javascript to change "Tab" to "Enter" Button. When we press Tab, it is like when we press Enter

Expand|Select|Wrap|Line Numbers
  1. button.if(oTarget.type=="text" && oEvent.keyCode==13) 
  2.     //return false;
  3.     oEvent.keyCode = 9;
  4.  }
I think you meant that the other way around.

Try enterToTab

Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
You can't set the keyCode like that in Firefox and other non-IE browsers.

Set the focus to the next text field instead by using the form.elements array and the focus() method.
May 3 '08 #2

100+
P: 210
. The use of this javascript to change "Tab" to "Enter" Button. When we press Tab, it is like when we press Enter

Expand|Select|Wrap|Line Numbers
  1. button.if(oTarget.type=="text" && oEvent.keyCode==13) 
  2.     //return false;
  3.     oEvent.keyCode = 9;
  4.  }
I think you meant that the other way around.

Try enterToTab
May 3 '08 #3

P: n/a
very good
thank you!
Oct 6 '10 #4

Post your reply

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