[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1201
  • Last Modified:

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?
0
markdot
Asked:
markdot
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now