J. VerSchave said:
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.