Page 1 of 1

Tabbing in a textarea?

Posted: Mon Aug 14, 2006 4:55 pm
by JellyFish
How do you make it to where when you press the "Tab" key in a textarea, it doesn't go to the next element in the page but rather have it really insert a tab?

Posted: Mon Aug 14, 2006 5:02 pm
by MarK (CZ)
just untested idea (should work though) - i would go for a onkeydown event, find out the code of the tab key, and then test the event for it. If tab was pressed, insert \t and return false.

Posted: Mon Aug 14, 2006 5:08 pm
by MarK (CZ)
Ok, here it is:

Code: Select all

<textarea id='tarea' onkeydown='if (event.keyCode == 9) {this.value += "\t"; return false;}'></textarea>

Posted: Mon Aug 14, 2006 5:11 pm
by JellyFish
WORKS LIKE A FLIPPIN CHARM! Thanks a $#!t load dude! :D

EDIT: One Problem though. When I try to insert a tab within the middle of text it just adds the tab at the end. Is there a way of getting around this one?

Maybe if we we could get the current selection of the textarea. Or something simular.

Posted: Mon Aug 14, 2006 11:19 pm
by nickvd
Take a look at this page: http://weblogs.asp.net/skillet/archive/ ... 95838.aspx ... i didnt test it out, but it may be a start...

Posted: Tue Aug 15, 2006 1:28 am
by matthijs
Take a look at this page: http://weblogs.asp.net/skillet/archive/ ... 95838.aspx ... i didnt test it out, but it may be a start
is IE6-only code, doesn't work in FF. But might be a start, indeed

Posted: Mon Aug 21, 2006 10:55 pm
by JellyFish
I don't get it? Is there an example of what scott is trying to do (in the link)?

Posted: Sun Jan 14, 2007 4:58 am
by JellyFish
Is there a way to find out where the clients character position was in the textarea?

Posted: Sun Jan 14, 2007 7:55 am
by thiscatis
using the this.select and a character count?

Posted: Sun Jan 14, 2007 9:04 am
by Kieran Huggins
this article should help:
http://www.webreference.com/programming/javascript/ncz/

uses createTextRange() for IE

Posted: Sun Jan 14, 2007 1:26 pm
by JellyFish
I'm really having a hard time following this artical. I don't know why. What property or method would I use on the textarea to get the character position of the client?

element.property/method

Posted: Sun Jan 14, 2007 2:15 pm
by Kieran Huggins
Moz and IE have different (both proprietary) systems when it comes to this.

This helped me when I needed it:
http://www.faqts.com/knowledge_base/vie ... /aid/13562