JS Resize Textarea Doesn't Work In Firefox

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

JS Resize Textarea Doesn't Work In Firefox

Post 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?
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

Ahem.
It does work in FireFox if you include a col value on your textarea :oops:
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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.
User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

Post 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
Post Reply