Use onkeypress even
see this example :http://jsfiddle.net/kevalbhatt18/bkyxz8cc/3/
<textarea id="txt" placeholder="name" class="form" type="text" onkeypress="this.style.width = ((this.value.length + 1) * 8) + 'px';"></textarea>
And for placeholder on load use jquery and apply placeholder
size in to input
$('textarea').css('width',((input.getAttribute('placeholder').length + 1) * 8) + 'px');
Even you can use id instead of input this is just an example so that I
used $(input)
And in css provide min-width
.form {
border: 1px solid black;
text-align: center;
outline: none;
min-width:4px;
}
If you remove all text from textarea box then it will take
placeholder value using focusout
$("textarea").focusout(function(){
if(this.value.length>0){
this.style.width = ((this.value.length + 1) * 8) + 'px';
}else{
this.style.width = ((this.getAttribute('placeholder').length + 1) * 8) + 'px';
}
});
For change the fontsize and the textarea resize
use button click
$('button').on('click',function(){
var style={
"font-size":"20px",
"height":"90px",
"width":"40%",
}
$('textarea').css(style);
})