473,396 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Controlling the function of the tab key on in a TEXTAREA field

I am curious if there is a way to handle this... maybe with Javascript...

Is there a way to set a TEXTAREA field so that the tab key on the
user's keyboard will create a tab within the text rather than tabbing
to the next field on the form?

Thanks.

-j
Jul 23 '05 #1
4 1820
In article <c5**************************@posting.google.com >, carlisle411
@yahoo.com enlightened us with...
I am curious if there is a way to handle this... maybe with Javascript...

Is there a way to set a TEXTAREA field so that the tab key on the
user's keyboard will create a tab within the text rather than tabbing
to the next field on the form?


If there is, it will then render the UI unusable to some people with
disabilities who rely on the tab key to move between fields.

Screwing with the UI is usually a Bad Idea.
The tab key is for moving between fields. The enter key usually submits a
form. The F5 key refreshes. Users count on a consistent UI.

You may want to consider having a special button that inserts a tab after the
existing text in the textarea instead. (I haven't checked on this and don't
know if it can be done, but I know inserting other characters at the end
works in most modern browser; inserting in the middle at the cursor position
or whatnot can be difficult.)

Just something to think about if this is for general internet use.

--
--
~kaeli~
Do cemetery workers prefer the graveyard shift?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
J. VerSchave wrote:
Is there a way to set a TEXTAREA field so that the tab key on the
user's keyboard will create a tab within the text rather than tabbing
to the next field on the form?


Kaeli's already stressed the risk of doing so; you might (will) break
accessibility for your users, so that's not something you'll want to do
eventually.

However, this can be done in IE5+ and latest Mozilla (I'm not satisfied
with Mozilla results, but haven't OTOH really tried to find an optimum
solution).
<textarea rows="10"
cols="30"
onkeydown="tab(this,event)"></textarea>

<script type="text/javascript">
function tab(ta,evt){
if(ta.createTextRange) { // assume IE's model
(function(){
var rng=null;
ta.onblur=function(){if(rng){rng.select();rng=null ;}}
ta.onkeydown=function(){
if(window.event.keyCode==9)
(rng=document.selection.createRange()).text="\t";
}
ta.onkeydown();
})();
} else if(ta.setSelectionRange) { // assume Mozilla's model
ta.onkeydown=function(evt){
if(evt.keyCode==9) {
var t=this, start=t.selectionStart, end=t.selectionEnd;
t.value=t.value.substring(0, start)+"\t"+t.value.substr(end);
t.setSelectionRange(start+1,start+1);
setTimeout(function(){t.focus();},1);
}
}
} else {
ta.onkeydown=null;
}
}
</script>
HTH,
Yep.
Jul 23 '05 #3
Yann-Erwan Perio wrote:
J. VerSchave wrote:
Is there a way to set a TEXTAREA field so that the tab key on the
user's keyboard will create a tab within the text rather than tabbing
to the next field on the form?

Kaeli's already stressed the risk of doing so; you might (will) break
accessibility for your users, so that's not something you'll want to do


As a suggestion, why not use "Ctrl+tab" rather than plain
"tab"? It seems to be pretty standard for inserting tabs in
table cells in a word processor, so why not for HTML
textarea too?

Cheers, Rob.
Jul 23 '05 #4
RobG wrote:
As a suggestion, why not use "Ctrl+tab" rather than plain "tab"? It
seems to be pretty standard for inserting tabs in table cells in a word
processor, so why not for HTML textarea too?


This seems indeed to be a much better idea, all the more it should
silence the accessibility problem (unless some browser implements both
ranges and CTRL+TAB, but I know of none). The initial script changes to
the following.
<textarea rows="10"
cols="30"
onkeydown="tab(this,event)"></textarea>

<script type="text/javascript">
function tab(ta,evt){
if(ta.createTextRange) { // assume IE's model
(function(){
var rng=null;
ta.onblur=function(){if(rng){rng=null;this.focus() ;}}
ta.onkeydown=function(){
if(event.keyCode==9 && event.ctrlKey)
(rng=document.selection.createRange()).text="\t";
}
ta.onkeydown();
})();
} else if(ta.setSelectionRange) { // assume Mozilla's model
ta.onkeydown=function(evt){
if(evt.keyCode==9 && evt.ctrlKey) {
var t=this, start=t.selectionStart, end=t.selectionEnd;
t.value=t.value.substring(0, start)+"\t"+t.value.substr(end);
t.setSelectionRange(start+1,start+1);
setTimeout(function(){t.focus();},1);
}
}
} else {
ta.onkeydown=null;
}
}
</script>
Cheers,
Yep.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John | last post by:
Hi, Would appreciate any help in in generalizing the following so that one can input from a form any number one wishes. var s; var t; var u; var v; var w;
9
by: Roger Withnell | last post by:
Tearing hair out time! Simple attached page shows the problem. http://www.brilley.co.uk/TestFocusSelect.htm Using a function to test if too many characters have been keyed in to a textarea....
3
by: effendi | last post by:
Is there a way I can control the number of lines a user enters in a textarea? I like to allow user to enter let say 5 lines and no more than that. Thanks in advance.
5
by: Mainard | last post by:
Hi, all First off I know alittle about javascript, but i have never worked with controlling froms with it be for i wonder can some help me? for example:I have this <textarea name"write1">Write...
3
by: leo | last post by:
Hello Guys I have this problem in controlling a text in a Text Area. How can I do that, for example the field size is 200, when it reaches 50 it automatically goes to the next line. Because im...
12
by: PMA | last post by:
Hi all, I am porting a web application from IE 6.0 to FireFox 1.5. I have solved almost all compatibility issues (quite a lot but not too bad) except two of them : 1) Clipboard access thru'...
5
by: mijman2 | last post by:
Hello, I want to click a button which sends the name of an input field to the function. From there I want the function to take the value of that input field, split it by the "/" symbol, take the...
23
by: Angus | last post by:
Hello I have a DIV with various elements eg: <div ARID="8" ARType="Char" ARDBN="Short Description"> <label class="label f9" for="arid8"Short Description</label> <textarea class="text sr "...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.