0

I have a text area which is editable. When we enter text in the textArea, the font size of the text change with the change in the text length. The greater the text length, smaller the font-size. This causes problems in the justification, is there any way I can justify the text inside the text area.

Here is the JavaScript Code:

var textie = document.getElementById('new1');
var spanny = document.getElementById('length');
var textLength;
textie.addEventListener('keypress',function(e){
var size;
textLength = textie.value.length;  
size = Change(textLength);
this.style.fontSize = size;
},false);

function Change(fontLength) 
{
var fontSize;
if(fontLength>=1 && fontLength<=4)
{
    fontSize = 35+"px";
}
else if(fontLength>=5 && fontLength<=12)
{
    fontSize = 30+"px";
}
else if(fontLength>=13 && fontLength<=35)
{
    fontSize = 20+"px";
}
else if(fontLength>=36 && fontLength<=50)
{
    fontSize = 18+"px";
}
else if(fontLength>=51 && fontLength<=150)
{
    fontSize = 16+"px";
}
else if(fontLength>150)
{
    fontSize = 15+"px";
}
return fontSize;
}

Here is the HTML

<textArea class = "new" id = "new1"></textArea>
<span id = "length"></span>

I am attaching a jsfiddle, try adding (lots of) random text in it and you will understand

Thanks!

Amir
  • 1,328
  • 2
  • 13
  • 27
theRev
  • 109
  • 1
  • 2
  • 12

1 Answers1

0

There are nothing wrong with your script. Actually, TextArea text justifying is not supported by major browsers.

rkawano
  • 2,443
  • 22
  • 22
  • So, is there no way I can align text in the text area. – theRev Dec 02 '13 at 06:19
  • Actually, no. But you can look for alternatives. See this: http://stackoverflow.com/questions/427039/justify-text-in-a-html-xhtml-textarea – rkawano Dec 02 '13 at 13:27
  • thanks for the help, I think its really not possible to justify text in a textArea without using a widget. Thanks though!! – theRev Dec 03 '13 at 05:13