I hope that helps! (In fact, ima go test it now too..)
Edit: Didn't work in Firefox.. sorry.. It seems the onkeypress attribute is not called by the TAB key for individual elements, the browser gets it first, and changes focus..
feyd wrote:map it to an access key, or something..
How can I map the TAB key to an access key? accesskey="tab"
System Wisdom... I'll test the idea... still get the feeling the tab key will take the curosr out of the focus of the box ( which.focus() should fix it).
feyd wrote:I meant make an access key insert a tab.
Ah... I get ya. I'll have to do that if I can't get it to work any other way.
SystemWisdom's code does print "\t" into the box in FF but not in IE. Just to scatter things too... my addition of which.focus() is working in IE but not in FF. I'd be a bit happier if both worked in one or t'other as opposed to half in IE and half in FF LOL
I'm trying it on IE6 at work (we dont have any other browser for me to test on).
The tab key just jumps out of the textarea (and onto the Browser controls) and no "\t" is outputted.
I managed to prevent that with a simple onBlur="this.focus()" (that's ok by the way - the textarea is the only major object on the page) but it still doesn't register the "\t" character into the textbox. Hmm.. I tried displaying an alert for the keyCode and it does 47 for / and 35 for # etc as expected but TAB is ignored.
Do you have an example of how you have implemented it and seen it work?
After a quick look at the JS code in this forum (sorry ) I have learnt how to track the cursor position and put the tab there (if the browser supports it), if it's unspupported the function will do what it did before -> put the tab at the end. This is nicer since you can edit the text and add tabs mid-text. Just a few extra lines did the trick.
BTW - The cancelBubble must be IE only since it doesn't work in Moz at all. It just tabs to the Browser controls etc. not sure if I can get it cross browser compatible
Yeah! that cancelBubble thingy comes under IE's DHTML implementation and is not implemented by others. Atleast, as much as I have heard so. It prevents the event from travelling up the event handler hierarchy.