Tabbing in MODx Manager (Administative)

One of the most annoying things about text boxes on the internet that seek to mimic a desktop publisher, is that you can never TAB inside of them.  The TAB always takes you to the submit button or the to the next form element.

Seriously, how do they expect you to keep you code nice and neat when you can’t TAB?

If you are using MODx….or any webpage that has a TEXTAREA…..where you find yourself needing to TAB, here a little javascript to fix all your troubles:

<script language="javascript" type="text/javascript">
function check(e){
if(e.keyCode == 9){ //If TAB, insert a TAB instead of going to next FORM field
e.returnValue = false;
t = e.currentTarget;
i = t.selectionStart;
text = t.value;
t.value = text.substring(0, i) + "\t" + text.substring(i);
Then in your textarea element, put this attribute: onkeydown=”check(event)”.  So it looks like this:
<textarea name="code" onkeydown="check(event)">Code Here</textarea>
This only works in Firefox, Chrome, and possibly Opera and Safari.  Internet Explorer will need additional code as it does not handle selectionStart.   I have only tested in Chrome, so please post your findings in the comments so others can stay up to date.  You can do this in Internet Explorer, but it will require additional code.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: