TextArea tab size

Hi,

In textarea, when display text with tabs, the tab size is 8 by default.
How to set the tab size to 4 in a textarea?
markdotAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aherpsCommented:
Not as far as I know - however, you can use javascript to override the tab character to 4 spaces.

Not really ideal, but here is a link the code:

http://ajaxian.com/archives/handling-tabs-in-textareas
0
markdotAuthor Commented:
I think the link you gave me is for insert tabs. I need is to set the tab size of the textarea. Say, when paste text from notepad, I want the tabs in the text have size = 4.
0
Lolly-InkCommented:
It sounds like you are displaying text that already exists, rather than typing text into the textarea.
If all tab characters are at the beginning of the line (for indenting purposes) then you can use this code to replace tab characters with 4 spaces:

<html>
<script>
   function formatTextArea()
   {
      var textArea = document.getElementById("textArea1");
      textArea.innerText = textArea.innerText.replace(/\t/g, "    ");
   }
</script>
<body onload="formatTextArea()">
   <textarea id="textArea1" rows="10" cols="100">function formatTextArea()
{
	var textArea = document.getElementById("textArea1");
	textArea.innerText = textArea.innerText.replace(/\t/g, "    ");
}</textarea>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lolly-InkCommented:
Or perhaps call the formatTextArea function assigned to the onchange event of the textarea element.
0
markdotAuthor Commented:
"assigned to the onchange event of the textarea" is good......but I don't want the tab be replaced with spaces, I need the tabs remain tabs but their size is changed to 4.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.