Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 3rd, 2003, 03:39 PM
Authorized User
Points: 447, Level: 7
Points: 447, Level: 7 Points: 447, Level: 7 Points: 447, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Adrian, MI, USA.
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default enter instead of tab

This may be a request that I have to tell the user to "forget it" but none the less I'll try. I have an html form with roughly 30 numeric fields which the user says she can fill in alot faster if she can use the 10 key and hit the enter on the 10key without having to use the second hand and reach for the tab key to move from field to field. I know I don't need to say this but when she hits the enter key it fires the submit button. Is there anything I can do for this poor soul?
Reply With Quote
  #2 (permalink)  
Old September 4th, 2003, 04:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try something like this which tests for enter key (13) and if it was pressed in a text box then it changes it to a tab (9) - seems to work in IE6 but I haven't tested it in any other browsers
Code:
<script language="javascript" type="text/javascript">
<!--
document.onkeydown = checkKey;

function checkKey(oEvent){
  var oEvent = (oEvent)? oEvent : event;
  var oTarget =(oEvent.target)? oEvent.target : oEvent.srcElement;
  if(oTarget.type=="text" && oEvent.keyCode==13) 
    //return false;
    oEvent.keyCode = 9;
}

// -->
</script>
Reply With Quote
  #3 (permalink)  
Old September 4th, 2003, 03:25 PM
Authorized User
Points: 447, Level: 7
Points: 447, Level: 7 Points: 447, Level: 7 Points: 447, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Adrian, MI, USA.
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That script rocks man, thanks.
Reply With Quote
  #4 (permalink)  
Old February 24th, 2005, 01:26 PM
Registered User
 
Join Date: Feb 2005
Location: Nashville, tn, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This enter key code works great accept when it gets to an Visual Interdev ASP dropdown box. . great work but do you have any suggestions for the dropdowns? You can only use the tab key in the dropdowns.

thank you



<script language="javascript" type="text/javascript">
<!--
document.onkeydown = checkKey;

function checkKey(oEvent){
var oEvent = (oEvent)? oEvent : event;
var oTarget =(oEvent.target)? oEvent.target : oEvent.srcElement;
if(oTarget.type=="text" && oEvent.keyCode==13)
    //return false;
    oEvent.keyCode = 9;
}

// -->
</script>
[/code]
[/quote]

tpiro
Reply With Quote
  #5 (permalink)  
Old February 25th, 2005, 04:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

that's because the original script was deliberately restricted to text boxes only, by adding the part if(oTarget.type=="text" ...

if you want to extend it to other html elements like the select you can add those types in too:
if((oTarget.type=="text" || oTarget.type=="select-one" || oTarget.type=="select-multiple")&& oEvent.keyCode==13)

hth
Phil
Reply With Quote
  #6 (permalink)  
Old March 9th, 2005, 10:26 PM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Nice script! I'm trying to make it work in Mozilla/Firefox besides IE; but it doesn't work for some reason (the page form is submitted instead and tab emulation doesn't work). I changed the event handler code to the following:

Code:
if(document.all)
{
    document.onkeydown = checkKey; // IE
}
else
{
    document.addEventListener('keydown', checkKey, false); // Mozilla
}
Any clues on how to make it work in Mozilla/Firefox.

Thanks!
Reply With Quote
  #7 (permalink)  
Old March 10th, 2005, 06:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

the original should work in Mozilla/Firefox as they both support the syntax document.onkeydown = checkKey . And these 2 lines:
  var oEvent = (oEvent)? oEvent : event;
  var oTarget =(oEvent.target)? oEvent.target : oEvent.srcElement;
have been used to cater for either the IE or Moz method of passing the event and getting the target.

Did you try the original before you modified it?

I don't have access to a Mozilla or Firefox browser at the moment to try it out, but I'll give it a go later.

rgds
Phil
Reply With Quote
  #8 (permalink)  
Old March 13th, 2005, 01:27 AM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Phil,

Thanks for your reply. I tried the original code (posted by you back in 2003) and it doesn't seem to work in Mozilla/Firefox. It works just fine in IE6. In Firefox, the form is submitted and the page is reloaded if the enter key is pressed. I'm not quite sure what could be the problem. I would really appreciate if you can have a look at it and help me resolve this problem.

Cheers!
Reply With Quote
  #9 (permalink)  
Old March 14th, 2005, 06:29 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

While researching this problem I came across this article which claims that Mozilla based browsers won't let you change the keyCode in script, so maybe there is no way to make it work in these browsers
http://www.faqts.com/knowledge_base/view.phtml/aid/1661
Reply With Quote
  #10 (permalink)  
Old March 31st, 2005, 09:00 AM
Registered User
 
Join Date: Mar 2005
Location: , , Netherlands.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I already searched a long time for code to use enter as a tab. Now I found this, i pasted it into my aspx page but it doesn't work.
Can someone tell me what could be wrong?

Thx

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to disable a tab on a tab control. dbradley VB.NET 6 April 14th, 2011 10:04 AM
Enter Key Event (Enter Key Only) Coby Excel VBA 0 February 6th, 2008 09:55 PM
Enter Like TAB leorochab C# 2005 2 May 19th, 2006 12:38 PM
using enter key as tab but not in multiline listbo sdduffer General .NET 1 March 30th, 2005 02:29 AM
Using the TAB ORDER with ENTER KEY ? thomaz C# 0 September 10th, 2003 08:10 AM



All times are GMT -4. The time now is 11:38 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.