Page 1 of 1

JS Resize Textarea Doesn't Work In Firefox

Posted: Mon Nov 28, 2005 11:21 am
by Grim...
Here is the code

Code: Select all

<!-- Begin Textarea Grower
    var agt=navigator.userAgent.toLowerCase();
    function grow(t) {
    a = t.value.split('\n');
    b=1;
    for (x=0;x < a.length; x++) {
     if (a[x].length >= t.cols) b+= Math.ceil(a[x].length/t.cols);
     }
    b+= a.length;
    if (b > t.rows && agt.indexOf('opera') == -1) t.rows = b;
    }
    
    // End -->
Basically, this causes the text area to resize as more text appears in the textarea (using onkeyup="grow(this)"; in the textarea).
It works fine in IE, in Opera it puts the caret back to the start of the textarea each time you press a key so that's trapped :roll:
In FF it just doesn't resize the textarea.
Any idea why not, or how I could do it so it does?

Posted: Mon Nov 28, 2005 12:18 pm
by Grim...
Ahem.
It does work in FireFox if you include a col value on your textarea :oops:

Posted: Mon Nov 28, 2005 12:40 pm
by Roja
Grim... wrote:Ahem.
It does work in FireFox if you include a col value on your textarea :oops:
Interesting! I didn't think col was required.. hrm. This might actually be a bug if thats not required in the standard.

Posted: Tue Nov 29, 2005 3:22 am
by Weirdan
Roja wrote:Interesting! I didn't think col was required.. hrm. This might actually be a bug if thats not required in the standard.
It may not be required to display the textarea itself, but to use the cols value in the script it seems quite natural that the 'cols' attribute is required.

Posted: Wed Dec 07, 2005 9:00 am
by phpdevuk

Code: Select all

var agt=navigator.userAgent.toLowerCase();
    function grow(t) { 
    a = t.value.split('\n'); 
    b=1; 
    for (x=0;x < a.length; x++) { 
     if (a[x].length >= t.cols) b+= Math.ceil(a[x].length/t.cols); 
     } 
    b+= a.length; 
    if (b > t.rows && agt.indexOf('opera') == -1) t.rows = b; 
    if (b < t.rows && agt.indexOf('opera') == -1) t.rows = b;     
    }
grows and shrinks :D