9lessons programming blog
Loading Search
Sunday, March 7, 2010

Facebook like Expanding Textbox with Jquery.

I received a email request from my reader that asked to me how to implement Facebook like expanding textbox with Jquery. So I had developed a simple tutorial. Take a look at this live demo

Facebook like Expanding Textbox with Jquery.

Download Script     Live Demo

Javascript Code
It works with Jquery latest version 1.4.2. $('#content').focus(function(){} - content is the ID of the textbox. Using $(this).animate() expanding textbox height and using $("#button_block").slideDown() showing the update button.
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function()
{

$("#content").focus(function()
{
$(this).animate({"height": "85px",}, "fast" );
$("#button_block").slideDown("fast");
return false;
});

$("#cancel").click(function()
{
$("#content").animate({"height": "30px",}, "fast" );
$("#button_block").slideUp("fast");
return false;
});

});
</script>

//HTML Code

<form method="post" action="">
<textarea  id="content"></textarea>
<div id="button_block">
<input type="submit" id="button" value=" Share "/>
<input type="submit" id='cancel' value=" cancel" />
</div>
</form>



CSS Code
#content
{
width:450px; height:30px;
border:solid 2px #006699;
font-size:14px;
}
#button
{
background-color:#006699;
color:#ffffff;
font-size:13px;
font-weight:bold;
padding:4px;
}
#cancel
{
background-color:#dedede;
color:#000;
font-size:13px;
padding:4px;
margin-left:10px;
}
#button_block
{
display:none;
}


Using testking 350-030 tutorials and testking 646-204 live demos, learn how to expand facebook textbox using jQuery. Become expert using our free testking 70-649 resources related to CSS, JavaScript and jQuery.
Sponsored Links

Share this post

Comments
{ 29 comments }
Gerben said...

Very nice! Thanks for sharing. Greets from the Netherlands.

Anonymous said...

Very nice. One thing though... you should make it expand it back up if the user clicks somewher else rather than the white space IF user has not entered any text in.

Alberto Rechy said...

Excellent, just as always!! 9 lessons is the best Jquery page I've ever found, congrats from Mexico!!!

Anonymous said...

sweet deal man...you are creating some VERY cool and useful things on this site...kudos my friend =]

Srinivas Tamada said...

@ Alberto Rechy

Thank You

bongolove said...

@I have learn a lot from this 9 lessons.
i real appreciate Srinivas Tamada,You are so blessed.
This is wonderful post.

Anonymous said...

What about post data?
How to fetch and post SQL?

Anonymous said...

What about post data?
How to insert/fetch from database?

Anonymous said...

OK... ignoring my previous post... <_<
this sucks.

Lingamaneni said...

Hi Srinivas

This is an excellent one....

Rebecca said...

This is awesome. I just can't figure out how to make it work with multiple textareas....help?

Anonymous said...

nice!

Anonymous said...

I'm sorry, but this form can't send any data?! How can i fetch the post data?

Thanks for helping me

Anonymous said...

good

rilwanfit said...

thanks dude..

asksuperuser said...

Nice but textbox not really expanding but just scrolling ;)

Sigit Hariono said...

Superb Srinivas Tamada, 9lessons is my fave Jquery Page. Indonesian siad Thanks for U a Lot.

shaughn said...

Very nice script..... this will be very useful thanx

sewa mobil said...

thanks for the info and explanation provided

SamsonDelila said...

Wow! Its nice... I'll add this trick to my website. You're awesome !

Anonymous said...

Awesome thanks! Can someone please share how to put the default "what's up" value? And have it vanish on click.

Anonymous said...

not work in IE7, getting errors on page...

Anonymous said...

Work in Firefox but not in Internet Explorer 8.

Karthik said...

xcellent codes................
frm KkK-146

Anonymous said...

If you are searching for a more mature version here you can find one http://fer-menta.blogspot.com/2010/12/jquery-expanding-textarea.html

It is a port from a dojo widget and work very well for me ;)

Saransh SuperNOVA Dhingra said...

I am impressed by the watermark javascript , the hiding and showing is fine , but watermark is good

Anonymous said...

I am a Mexican Too!

Anonymous said...

Hi i have problem with this script... It works perfect, but to first textarea on page. Is possible to change this script to work with multiple textareas ?

resume writing service said...

It works perfect, but to first textarea on page. Is possible to change this script to work with multiple textareas.
resume writing service

Post a Comment

Subscribe now!Recent Posts

Categories

Subscribe now!Popular Posts

People Says

@9lessons thank you for the great tutorials, we truly appreciate your contributions to the design community.

Smashing Magazine

Like Me

follow me
products

9lessons labs

9lessons clouds

Android application

Chrome Extension