Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-15-2009, 07:03 PM   PM User | #1
DJW
New to the CF scene

 
Join Date: Sep 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
DJW is an unknown quantity at this point
Can't replace Keycode for <space> with <Tab>

I have a 3 textareas that when the user presses the spacebar I would like for the code to execute a TAB to move between them instead. My code works if I make the replacement keycode an number or letter but it wont work if I use TAB. The browser is IE. Thank you for any help you can give.

<script type="text/javascript">
function keycode(e) {
if(e.keyCode==32) {return (e.keyCode=9);}
}
</script>
</head>
<body>
<form>

<input name="DefectNumber" id="DefectNumber" type="text" onkeypress="return keycode(event);">
<input name="DefectNumber2" id="DefectNumber2" type="text" onkeypress="return keycode(event);">
<input name="DefectNumber3" id="DefectNumber3" type="text" onkeypress="return keycode(event);">
</form>
</body>

Last edited by DJW; 09-15-2009 at 07:10 PM..
DJW is offline   Reply With Quote
Old 09-15-2009, 07:58 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
This will work in IE only:-

<body onkeydown="if (event.keyCode==32) {event.keyCode=9; return event.keyCode }">

Must be in <body> tag. Obviously that will apply to all fields.

Another method is to use the focus method of the element you want to focus.

Code:
</head>
<script type="text/javascript">
function move2(ev) {
var key;
ev = ev || event;
key = ev.keyCode;
alert (key);
if (key == 32) {
document.forms[0].DefectNumber2.focus();
return false;
}
}
</script>
</head> 
<body> 
<form>

<input name="DefectNumber" id="DefectNumber" type="text" onkeyup ="move2(event)">
<input name="DefectNumber2" id="DefectNumber2" type="text" onkeyup = "move3(event")>
<input name="DefectNumber3" id="DefectNumber3" type="text" >
</form>

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
Philip M is offline   Reply With Quote
Old 09-15-2009, 09:29 PM   PM User | #3
DJW
New to the CF scene

 
Join Date: Sep 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
DJW is an unknown quantity at this point
Thank you for your help.
Your code put me on the right path. I have a <TD> tag calling a function where I manipulate the keycodes. I have one more question if you wouldn't mind. Is there a way to pass multiple keycodes? In other words if I press the spacebar I would like it to simulate the TAB key being pressed twice.

Thank you again.
DJW is offline   Reply With Quote
Old 09-16-2009, 09:00 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by DJW View Post
Your code put me on the right path. I have a <TD> tag calling a function where I manipulate the keycodes. I have one more question if you wouldn't mind. Is there a way to pass multiple keycodes? In other words if I press the spacebar I would like it to simulate the TAB key being pressed twice.
What is the point of this, and why do you want to alter the default behaviour of the browser? When the user presses space, he expects to get a space, not a tab, still less two tabs. This sort of thing is guaranteed to annoy your users and drive them away from your site.

If you insist, use the script I gave you to move the focus to whatever location seems to please you.
Philip M is offline   Reply With Quote
Old 09-16-2009, 06:39 PM   PM User | #5
DJW
New to the CF scene

 
Join Date: Sep 2009
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
DJW is an unknown quantity at this point
This not a personal website it is a web-based test tracking tool that my company uses and there is no accelerator key capablity so I have tasked with creating them. I am actually not using the space bar I am using the down arrow, I was just looking for example help so that I could actually complete it myself.
DJW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 12:54 PM.


Advertisement
Log in to turn off these ads.