I found the enableTab() function and added it to the test script below.
What I would like to know is if it is possible to change the t offset length from the default 8 characters
to some other length, like 4 maybe?
[code]
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″ />
<title> Element Tabulation </title>
</head>
<body>
<textarea id=”TArea” cols=”80″ rows=”10″></textarea>
<br><button onclick=”document.getElementById(‘TArea’).value += ‘—-+’.strCreate(72)+’n'”> —-+ </button>
<button onclick=”document.getElementById(‘TArea’).value += ‘1t2t3t4t5t6t7t8t9t0n'”> 1…0 </button>
<script type=”text/javascript”>
String.prototype.strCreate = function(N) { // N = length of this string pattern to create
var str = ”;
while (str.length < N) { str += this; }
return str.substring(0,N);
}
// Following from: http://css-tricks.com/snippets/javascript/support-tabs-in-textareas/
function enableTab(id) {
var el = document.getElementById(id);
el.onkeydown = function(e) {
if (e.keyCode === 9) { // tab was pressed
// get caret position/selection
var val = this.value,
start = this.selectionStart,
end = this.selectionEnd;
// set textarea value to: text before caret + tab + text after caret
this.value = val.substring(0, start) + ‘t’ + val.substring(end);
// put caret at right position again
this.selectionStart = this.selectionEnd = start + 1;
// prevent the focus lose
return false;
}
};
}
window.onload = function() {
enableTab(‘TArea’);
}
</script>
</body>
</html>