0

There are two textareas which has the exact same text formatting. IDs are textareaA and textareaB.

I've set some stuff to happen for textareaA keyup. My question is How do I set a textareaB to resize its WIDTH while the user is typing in textareaA?

This is what I tried but no luck.

$(document).on("click blur keyup", ".fT", function() { // keyup responds with textareaA
        var newWidth = $("#textareaA").val(); //does not work
        $("#textareaB").width(newWidth);
});
Fergoso
  • 1,584
  • 3
  • 21
  • 44

2 Answers2

0

Use the .css("proprety", "value") JQuery Method to perform this.

Usage :

$(document).keyup(function(event)) {
    $("#textareaB").css("width", "1000px");
});

Usage (with variable) :

var myVariable = 1000; /* integer here */

$(document).keyup(function(event)) {
    $("#textareaB").css("width", myVariable.toString() + "px");
});
Anwar
  • 4,162
  • 4
  • 41
  • 62
0
 $('#TextAreaId').keyup(function(e) {
         while ($(this).outerHeight() < this.scrollHeight + parseFloat($(this).css("borderTopWidth")) + parseFloat($(this).css("borderBottomWidth"))) {
             $(this).height($(this).height() + 1);
         };
     });

EDIT 2: (Increase textarea width)

note ::change the value '8' in if according to your need and best fit

$(function() {   
$('#mta').keyup(function(e) {

    console.log($(this).outerWidth()+'--'+$(this).val().length*8);
         if($(this).outerWidth() > $(this).val().length) {
             $(this).width($(this).width() + 1);
         };
     });

 });
Dimag Kharab
  • 4,439
  • 1
  • 24
  • 45
  • Thanks. This adjusts the height? I'm looking for a solution which adjust its width. – Fergoso Feb 23 '15 at 12:59
  • My requirement is to set the width of the textarea to the length of its text only. E.g.: if there is a 6 word sentence or a 2 word sentence I would want the textarea to be only to its length of text. I want to avoid any unwanted length of the textarea. – Fergoso Feb 23 '15 at 13:10