...

View Full Version : How do you resize a textbox in javascript



bthumber
11-15-2010, 08:38 PM
I have an asp.net textbox. I need to use javascript so that there are no postbacks. I would like to click the button and the textbox height kept increases each time the user clicks the button. So far I can toggle:

function resize(){
var textbox = $get('<%=txtWhoTo.ClientID %>');
textbox.style.height = textbox.style.height == '56px' ? '23px' : '56px';
}

I would like to increase the height 56px each time the clicks the button.

Old Pedant
11-15-2010, 09:26 PM
First of all, it's *NOT* a "textbox". ASP.NET calls it that, but when an ASP.NET "textbox" is more than one line high, it's a <TEXTAREA> as rendered in HTML.

Anyway:


function resize()
{
var ta = $get('<%=txtWhoTo.ClientID %>');
ta.style.height = ( parseInt(ta.style.height) + 56 ) + "px";
}


It's probably not a good idea to name the function "resize" as that's a builtin event on at least the <body> object. Not sure about other objects.

If possible, just change the name. Even "Resize" (capitalize the first letter) would be better.

rnd me
11-15-2010, 11:17 PM
It's probably not a good idea to name the function "resize" as that's a builtin event on at least the <body> object. Not sure about other objects.


no it's not, onresize is...

Old Pedant
11-15-2010, 11:32 PM
Yes, I know the event is named onresize, but you *can* invoke it via a call to resize().

Maybe it's not important, not a big deal. Maybe it never causes conflicts. I'm just paranoid and avoid duplicating any built-in names I'm aware of.

bthumber
11-16-2010, 01:54 PM
Thanks for the help it works great! I changed the name of the function to something more discriptive IncreaseTBSize() and DecreaseTBSize. Now just for my knowledge you it is a testarea because it is more than one line, correct.

rnd me
11-16-2010, 08:57 PM
Maybe it's not important, not a big deal. Maybe it never causes conflicts. I'm just paranoid and avoid duplicating any built-in names I'm aware of.

never a bad idea...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum