Enlarge input fields on focus

Some time ago client insisted to be able to see all 500 characters while typing the text in input fields. Ok, reasonable. But they also insisted that web form should take the minimum space and that input fields should be "single line". Errr... "Oh I see", I said "so you want to make an oil painting using pencil, right? You can actually do it with JavaScript."

Doesn't matter if request sounds stupid or not, a solution is always needed. So I suggested to enlarge input fields on focus so that entire text could be visible during typing. I wasn't sure about usability, though, but the client was satisified. The solution was more than simple, and this is the example of it (I didn't make a demo because this is soooo simple):

$("textarea").focus(function(){
    $(this).width = 600; // enlarge width
}).blur(function(){
    $(this).width = 200; // return to original value
});

You can animate this as well:

$("textarea").focus(function(){
    $(this)).animate({ width:"600px"}, 1000); // enlarge width
}).blur(function(){
    $(this).animate({ width:"200px"}, 1000); // return to original value
});

Now, this might be a solution for many comment forms on various blogs because your website URL might not fit entirely in input field and this can be frustrating. The reason is simple - I, for example, submit my articles to many websites and my browser remembers my inputs, of course. So when I want to enter URL on some comment form I get this:

Which one to choose?

Oh, yes, input fields on these forms could be simply just larger, but hey... any sugesstions?

More articles in Blog archive or elsewhere
Advertisement

17 Comment(s)

Davide Espertini

Davide Espertini 06 Mar 2009 #

Simple and cool solution Janko! GREAT!! Laughing WOW

splatzone

splatzone 06 Mar 2009 #

Cool!

I wish there was a demo, it's the first thing I look for when I see an article like this -- even if it is amazingly simple.

Web Design

Web Design 07 Mar 2009 #

hmmm.... it so easy!

maybe add animation by height too? Add some arrow icon at the bottom in the right of textarea field?
Thanks

Sergejus

Sergejus 07 Mar 2009 #

Looks like nice solution, but I'm interested, does this work for the several inputs in the same row? Maybe in this situation it's better to change height, not the width?

Anyway, thanks for sharing your idea!

Vukasin

Vukasin 07 Mar 2009 #

I'm just gonna go with splatzone in asking for a demo - perhaps the site of your client?

Janko

Janko 07 Mar 2009 #

Davide, thanks Smile

Splatzone, Vukasin: Unfortunately that was intranet app, so int can't be seen. However, I'll add a small demo tonight when I get back home.

Web Design, Sergejus: Sure, horizontal stretch can also be implemented, depending on web form layout. Whatever fits best in your design! Arrow icon might not be necessary in this particular case because it is going to be stretched anyway when field get focus. Unless you meant just for notifying which fields are "stretchable" Smile

Weight Loss Programs

Weight Loss Programs 08 Mar 2009 #

i didn't know this trick is so simple. I will give it a try now.

veroljub

veroljub 09 Mar 2009 #

in second code you have two "))"

This is so cool solution but  I didnt manage to run it Frown

Marco

Marco 09 Mar 2009 #

Hmhm - I tried to do this too, but just like @veroljub, I can't get it to work. Could you still provide us with a demo? I'm on FF3 on Mac OSX, using jQuery 1.3.1 .

Damn, I feel stupid Frown .

Davide Espertini

Davide Espertini 09 Mar 2009 #

Friend, the sample code is incorrect. A plus ) is present in the code. The right code is:

$(this).animate({ width:"600px"}, 1000); // enlarge width

We have to eliminate one of the )    Laughing

The sample work correctly, only a little typing error by Janko Laughing

Davide Espertini

Davide Espertini 09 Mar 2009 #

I have make a little sample, see it in action at:

www.espertini.com/demoWarpSpeed/default.aspx

Janko I hope not to cause annoyance with this example before the publication of your example. Smile

Janko

Janko 09 Mar 2009 #

Veroljub, Marco, Davide: I haven't the idea why it's not working, but thanks to Davide, now I understand! Thanks, Davide on your help! I am quite busy and just don't manage to do the demo! Thanks!

Gilles D.

Gilles D. 10 Mar 2009 #

Nice idea. And why not enlarge the input while key typing ?

Davide Espertini

Davide Espertini 10 Mar 2009 #

I hope to be helpful to you and also to other users Laughing
Happy coding friends!

rakesh juyal

rakesh juyal 12 Mar 2009 #

DEMO Please Laughing

Davide Espertini

Davide Espertini 12 Mar 2009 #

I have created a little demo, you can see it in action here:

www.espertini.com/demoWarpSpeed/default.aspx

Laughing

rakesh juyal

rakesh juyal 12 Mar 2009 #

Cool! Smile

Comments are closed
via Ad Packs
9292