Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 3rd, 2003, 03:39 PM
Authorized User
 
Join Date: Aug 2003
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?
 
Old September 4th, 2003, 04:59 AM
Friend of Wrox
 
Join Date: Jun 2003
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>
 
Old September 4th, 2003, 03:25 PM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That script rocks man, thanks.
 
Old February 24th, 2005, 01:26 PM
Registered User
 
Join Date: Feb 2005
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
 
Old February 25th, 2005, 04:53 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old March 9th, 2005, 10:26 PM
Registered User
 
Join Date: Mar 2005
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!
 
Old March 10th, 2005, 06:18 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old March 13th, 2005, 01:27 AM
Registered User
 
Join Date: Mar 2005
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!
 
Old March 14th, 2005, 06:29 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old March 31st, 2005, 09:00 AM
Registered User
 
Join Date: Mar 2005
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






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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.