/    Sign up×
Community /Pin to ProfileBookmark

Can I change the length of a tab offset in text element

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>
[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@blasphemyJan 03.2014 — There is [url="http://www.w3.org/TR/css3-text/#tab-size"]tab-size property (CSS3)[/url].

Currently it's only implemented in Firefox and Opera (with vendor prefixes).

textarea {

-moz-tab-size: 4;

-o-tab-size: 4;

}
Copy linkTweet thisAlerts:
@JMRKERauthorJan 03.2014 — There is [url="http://www.w3.org/TR/css3-text/#tab-size"]tab-size property (CSS3)[/url].

Currently it's only implemented in Firefox and Opera (with vendor prefixes).

textarea {

-moz-tab-size: 4;

-o-tab-size: 4;

}[/QUOTE]


Thank you for that information.
Copy linkTweet thisAlerts:
@rootJan 04.2014 — Only thing I can suggest is to use a [B]RegExp[/B] to test and [B]replace[/B] all [B]t[/B] characters with [I]x[/I] spaces.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...