Current Article
Industry Buzz
Social Networking
Featured Articles
Browse Content >
Back to Home

How to Add Suggestion Text to Your Input Fields

Geordie Konrad
Want to add an extra bit of professionalism to your web forms? This snippet allows you to provide default values for the input fields in your web form that disappear when the user focuses on that field. Add functionality while saving space!

Introduction

This is a really easy snippet to implement, it's going to feel like a freebie. We need only two reusable JavaScript functions. The first handles when a user focuses on the field, and the second handles when a user removes that focus.

Here are the two functions in full.

JavaScript Functions

 
function handleFocus(element)
{
    
    if (element.value == element.defaultValue) 
    {
        element.value = '';
    }
  
}

function handleBlur(element)
{

    if (element.value == '')
    {
        element.value = element.defaultValue;
    }

}

Here they are in plain english.

handleFocus: If the newly focused element contains the suggestion text, empty the field.
handleBlur: If the element which just lost focus is now empty, replace with the suggestion text.

Creating our Input Fields

Finally, we need to set up each input field with proper 'onfocus' and 'onblur' event handling. Make sure to add your suggestion text in the 'value' attribute!




Live Demo

Conclusion

While there isn't much to implementing this snippet, the functionality it adds is sure to turn heads. Usability is the name of the game, and this is a great step towards making that a reality for your users.

Please post any comments/suggestions below. Feedback is always appreciated, it lets us know how we are doing and how we can better serve the community!

Share Article

User Comments

Gravatar
Jay
5/14/2009
Thanks for this. Very simple. I was pleasantly surprised to find out this also works with the asp:TextBox tag (the initial text specified in the Text='' property). I registered the client script on PageLoad.
Gravatar
kooluser
1/17/2010
thanks so much for this article
Gravatar
agiboire
4/15/2010
The best way to do it it's using CSS. This example is not working with a non javascript browser.

@tchaOo°
Gravatar
Pritesh Shah
9/15/2010
hello
Gravatar
Pritesh Shah
9/15/2010
hello
Gravatar
HIFU
9/14/2011
That was a fabulous performance, congratulation to you
http://www.hifurx.com/hifu/ HIFU
Gravatar
Ignacio
11/2/2011
Great!! Thanks a lot!!!!
Gravatar
JESUS
4/20/2012
Thank you. I'm using it in a job.
Gravatar
Hadriel
6/18/2012
I know this post is kind of old, but now you can use a HTML5 attribute, 'placeholder'. This makes it even more easy.
Gravatar
lnsfhwpk
12/22/2013
1
Gravatar
Oakley Outlet
8/28/2015
Hello!
Louis Vuitton Outlet Online: http://www.louisvuittonoutletonline.us.com/
Oakley Outlet,Oakley Sunglasses: http://www.oakley-outlet.us.com/
Coach Outlet,Coach Factory Outlet: http://www.coachoutletstore.us.com/
Coach Factory Outlet: http://www.coachoutlet-factoryonline.us.com/
Coach Outlet,Coach Factory Outlet: http://www.outletcoach.us.com/
Michael Kors Outlet: http://www.michaelkorsoutletonlines.us.com/
Michael Kors Outlet Online: http://www.michaelkorsoutletinc.us.com/
Michael Kors: http://www.michael-kors-outletonline.us.com/
Michael Kors Outlet: http://www.michaelkorsfactoryoutletonline.us.com/
Oakley Sunglasses,Oakley Vault Outlet: http://www.oakleysunglassesinc.us.com/
True Religion Outlet: http://www.truereligionoutlets.us.com/
Marc By Marc Jacobs: http://www.marcsbymarcjacobs.com/
Marc Jacobs Outlet: http://www.marc-jacobsoutlet.com/
Coach Factory outlet: http://www.coachfactory-outletstores.us.com/
Coach Outlet Stores: http://www.officialcoachoutletstores.com/
Sac Longchamp: http://www.sacportefeuillepascher.com/
Coach Outlet: http://www.coachoutletfactoryonline.us.com/
Michael Kors: http://www.michaelkorsfactorystore.us.com/
The North Face Outlet: http://www.outletnorthface.us.com/
coach handbags outlet: http://www.coachbagsoutlet.us.com/
Coach Outlet Store Online: http://www.coachonlinestore.us.com/
Ray Ban Pas Cher: http://www.raybanspascher.com/
porte monnaie chanel: http://www.portemonnaiechanel.com/
sac chanel blanc: http://www.sacblanc.com/
Ray Ban Sunglasses Outlet: http://www.raybanoutletsunglasses.us.com/
Ray Ban Sunglasses: http://www.raybanaviatorsunglasses.com/
portefeuille femme chanel: http://www.femmeportefeuille.com/
portefeuille chanel femme: http://www.portefeuillesfemme.com/
Cheap Ray Ban Sunglasses 90% off: http://www.raybansunglasses90off.com/
Ray Ban Sunglasses outlet,ray ban: http://www.sunglassesoff.com/
Chi Flat Iron,Chi Hair Official Website: http://www.chiofficialwebsite.com/
Coach Outlet: http://www.onlinecoachoutlet.us.com/
Toms Shoes,Toms Shoes Outlet Online: http://www.tomsshoe.us.com/
True Religion Outlet: http://www.truereligionoutletstores.us.com/
Oakley Outlet Store Online: http://www.oakleyoutletstoresonline.com/
Oakley Outlet: http://www.oakleyoutletstoreonline.us.com/
Bracelet hermes,sac chanel: http://www.sacportefeuilles.com/
Sac Chanel: http://www.portefeuillepascher.com/
Burberry Outlet Online: http://www.outletonlineburberry.com/
Oakley Sunglasses 90% off: http://www.oakleysunglasses90off.com/
Chanel Porte Monnaie: http://www.chanelportemonnaie.com/
Chanel Porte Monnaie Pas cher: http://www.portemonnaiepascher.com/
Valentino Rockstud shoes: http://www.valentino.com.co/
valentino shoes: http://www.valentinoshoes.com.co/
cheap coach handbags: http://www.cheapcoachhandbags.us.com/
Coach Outlet Stores Online: http://www.coach-outletstoresonline.us.com/
Coach Factory outlet: http://www.coachoutlet-factorystore.us.com/
Oakley Sunglasses Outlet: http://www.oakleyoutletsunglasses.us.com/
Oakley Sunglasses outlet: http://www.sunglassesoutletoff.com/
Tiffany And Co: http://www.tiffanyoutletstore.us.com/
Michael Kors Outlet: http://www.michaelkorssoutlet.us.com/
Coach Factory: http://www.coachoutletfactorystoresonline.com/
Christian Louboutin: http://www.christianlouboutins.us.com/
Valentino Shoes On Sale: http://www.valentinoshoeswebsite.com/
Christian Louboutin: http://www.christian-louboutinshoes.us.com/
Christian Louboutin: http://www.christianlouboutinshoesoutlet.us.com/
Beats Headphones Black Friday: http://www.beatsbydrdreheadphone.us.com/
Beats By Dre: http://www.beatsbydrdre.com.co/
Michael Kors Outlet: http://www.michael-korsoutlet.com.co/
Michael Kors Outlet Online: http://www.michaelkorsoutletonlineeco.us.com/
Tiffany And Co outlet 2015: http://www.tiffanyandco2015.com/
Tiffany And Co: http://www.coandtiffany.us.com/
Michael Kors handbags outlet: http://www.michaelkorshandbagsoutlet.us.com/
Beats By Dre headphones: http://www.beatsbydreheadphone.us.com/
cheap hair straighteners: http://www.cheaphairstraighteners.us.com/
Christian Louboutin shoes: http://www.christianlouboutinshoes.com.co/
Christian Louboutin: http://www.christian-louboutin.com.co/
lunettes ray ban: http://www.lunettesofficiel.com/
Coach Factory Outlet: http://www.coachoutletfactorystores.us.com/
Coach Outlet Online: http://www.coachoutletonlinesale.us.com/
Michael Kors Outlet: http://www.michaelkorsoutletonlinein.com/
Michael Kors Outlet: http://www.michaelkors-factoryoutlet.us.com/
Michael Kors Outlet Online: http://www.onlinemichaelkorsoutlet.us.com/
Oakley Sunglasses outlet: http://www.oakleysunglassesoutletonline.us.com/
True Religion Jeans outlet: http://www.true-religionjeans.com.co/
True Religion Jeans: http://www.truereligionoutletco.us.com/
Oakley Sunglasses: http://www.oakleycheapsunglasses.us.com/
Cheap Oakley Outlet: http://www.cheapoakleyoutlet.us.com/
Coach Outlet,Coach Handbags: http://www.coachoutletstores.us.org/
True Religion Jeans: http://www.truereligions.us.com/
ray-ban sunglasses,ray ban: http://www.ray-bansunglasses.it/
Oakley Sunglasses: http://www.oakleysunglasses.com.im/
Coach Outlet Store Online: http://www.coachonlinestoresoutlet.com/
Coach Outlet Online: http://www.coachoutletonlinecoachfactory.com/
Red Bottom Shoes: http://www.redbottomshoes.com.co/
Michael Kors Outlet: http://www.michaelkorsoutletco.us.com/
Toms Shoes Outlet Online: http://www.tomsshoeoutletonline.com/
True Religion Jeans: http://www.truereligionfactoryoutlet.us.com/
True Religion Outlet,True Religion: http://www.truereligionoutlet.us.org/
Ray-Ban Aviator Sunglasses: http://www.raybanaviatorsunglasses.com/
Ray Ban Outlet: http://www.raybanoutlet.us.com/
Ray-Ban Sunglasses: http://www.ray-bansunglasses.us.com/
Red Bottom Shoes,Red Bottom: http://www.redbottomshoe.us.com/
Tiffany And Co Jewelry: http://www.tiffanyandco.us.com/
Tiffany Outlet: http://www.tiffanyoutlet.com.co/
Tiffany And Co: http://www.andcotiffany.us.com/
Tiffany And Co jewelry outlet: http://www.tiffany.us.org/
valentino shoes On Sale: http://www.valentinoshoesonsale.com/
valentino outlet: http://www.valentinooutletshoes.com/
mocassin sac chanel: http://www.sacenpaille.com/
lunettes vue ray ban: http://www.raybanofficiel.com/
ray ban pas cher: http://www.lunettesdevue2015.com/
Beats By Dr Dre,Headphones: http://www.beatsbydrdre.us.com/
Red Bottom Shoes for women: http://www.red-bottomshoes.us.com/
Tiffany And Co,Tiffany Outlet: http://www.tiffanyandco.us.org/
Tiffany And Co jewelry: http://www.tiffanyandcojewelry.us.com/
Ray Ban Outlet: http://www.ray-banoutlet.us.com/
Chi Flat Iron: http://www.chiflatiron.org/
Chi Flat Iron official website: http://www.chiflatironblackfriday.com/
Ray Ban Sunglasses: http://www.raybansunglassess.us.com/
Cheap Ray Ban Sunglasses: http://www.cheapraybansunglasses.com.co/
True Religion Jeans On Sale: http://www.truereligion-jeans.us.com/
True Religion Jeans: http://www.true-religionjeans.us.com/
Christian Louboutin Heels: http://www.christianlouboutinheels.com/
Model De Sac Chanel: http://www.modeldesac.com/
Model De Sac Chanel pas cher: http://www.modeldesacpascher.com/
Christian Louboutin: http://www.christianlouboutinco.us.com/
Christian Louboutin shoes Outlet Online: http://www.clshoesoutletonline.com/
Beats By Dre Black Friday: http://www.beatsbydreblackfriday.us.com/
Cheap Beats By Dre: http://www.cheapbeatsbydre.us.com/
Cheap Ray Ban Sunglasses: http://www.raybancheapsunglasses.us.com/
Ray Ban Outlet Store: http://www.raybanoutletstore.com/
Toms Shoes Outlet Online: http://www.tomsoutlet.us.com/
Louboutin shoes: http://www.louboutinshoes.com.co/
Louboutin Outlet: http://www.louboutinoutlet.com.co/
Hermes Belt,Hermes Outlet: http://www.hermesbeltsoutlet.com/
Hermes Bag,Hermes Handbags: http://www.hermesbag.us.com/
Gucci Handbags,Gucci Shoes,Gucci: http://www.guccishoesoutletonline.com/
Christian Louboutin shoes: http://www.louboutin.us.com/
Cheap Nike Air Max: http://www.cheapnikeairmaxes.com/
Coach Outlet Store Online: http://www.coachoutlet-storeonline.com/
Chanel Handbags,Chanel Purses: http://www.chanelhandbagswebsite.com/
Chi Flat Irons: http://www.chiflatirons.com.co/
Toms Shoes Outlet Online: http://www.tomsshoesoutletonlines.com/
Coach Outlet,Coach: http://www.coach-factory-outletonline.us.com/
Ray Ban Wayfarer Sunglasses: http://www.raybanwayfarersunglasses.com/
Sac Chanel Blanc Pascher: http://www.sacblancpascher.com/
Sac Chanel Vuir Blanc: http://www.sacsblanc.com/
Coach Factory Outlet Online: http://www.factorystoreonline.com/
Coach Purses Outlet: http://www.coachpursesoutlet.us.com/
Michael Kors: http://www.onlinemichaelkors.us.com/
Michael Kors Outlet: http://www.michaelkorsstoreoutlet.us.com/
Beats By Dre Headphones: http://www.beatsbydreheadphones.com.co/
Gucci Outlet,Gucci Handbags: http://www.outletgucci.us.com/
Coach Outlet: http://www.coach-outlet-online.us.com/
Valentino Shoes,Valentino: http://www.valentinoshoes.us.org/
Louis Vuitton Outlet: http://www.louisvuitton-outletsale.com/
Louis Vuitton: http://www.louisvuitton.us.org/
Michael Kors purses outlet: http://www.michaelkorspursesoutlet.us.com/
Michael Kors Handbags: http://www.michaelkorshandbags.us.com/
Louis Vuitton Outlet: http://www.louisvuittonoutlet-store.com/
Louis Vuitton Outlet: http://www.louis-vuitton-outlet-online.com/
Louis Vuitton Outlet Online: http://www.louisvuittonoutlet-online.com/
Valentino Sandals: http://www.valentinosandals.com/
Valentino Rockstud: http://www.valentinorockstudshoes.com/
Louis Vuitton Outlet: http://www.louis-vuittonus.com/
Louis Vuitton Outlet Stores: http://www.outletonlinelouisvuitton.com/
Sac Louis Vuitton: http://www.saclouisvuittons.com/
Kate Spade Outlet: http://www.katespadeoutletonline.us.com/
Kate Spade outlet Online: http://www.katespadesoutlet.us.com/
Red Bottom Shoes: http://www.redbottomshoes.us.com/
Beats Headphones Black Friday: http://www.beatsheadphonesblackfriday.us.com/
Toms Shoes: http://www.tomsshoes2015sale.com/
Chi Official Website: http://www.chiflatirons.us.com/
Cheap Oakleys: http://www.cheapoakleys.us.com/
Oakley Outlet: http://www.oakleyoutlet.com.co/
Coach Outlet: http://www.coachoutletfactorystore.com/
Michael Kors: http://www.michaelkorsoutletsstore.cc/
Sac Hermes,sac hermès birkin: http://www.pascherhermes.com/
Giuseppe Zanotti: http://www.giuseppezanottishoe.com/
Chanel Handbags,CoCo Chanel: http://www.coco-chanel.us.com/
Tiffany Outlet: http://www.tiffanyoutlet.us.org/
Tiffany And Co Jewelry Outlet Online: http://www.jewelryoutlet.com.co/
Chi Flat Iron Official: http://www.chiflatironofficial.us.com/
Chi Flat Iron 2015 sale: http://www.chiflatiron2015.com/
Burberry Outlet Online: http://www.burberryoutlet-online.us.com/
True Religion Outlet Jeans: http://www.truereligionoutletjeans.us.com/
True Religion Outlet Store Online: http://www.jeansoutlet.com.co/
Chanel Handbags,Chanel Outlet: http://www.chanel-outlet.us.com/
Prada Outlet,Prada Handbags: http://www.pradaoutlet.eu.com/
Prada Handbags: http://www.pradahandbags.eu.com/
Prada Handbags Outlet: http://www.pradahandbags.us.org/
Marc By Marc Jacobs: http://www.marcbymarc-jacobs.com/
Celine Handbags: http://www.celine-handbags.com/
Celine Handbags Outlet: http://www.celinehandbags.us.com/
Valentino Wedges: http://www.valentinowedges.com/
Valentino Boots: http://www.valentinoboots.com/
Ray Ban Sunglasses: http://www.ray--bansunglasses.us.com/
Oakley Sunglasses: http://www.oakleyglasses.us.com/
Ray Ban Sunglasses: http://www.cheapraybansunglasses.us.com/
Ray Ban Sunglasses: http://www.rayban-sunglasses.us.com/
Cheap Ray Ban Sunglasses: http://www.cheaprayban.us.com/
Ray Ban Glasses: http://www.ray-bans.us.com/
Oakley Sunglasses: http://www.oakleysunglasseswebsite.com/
Cheap Oakley Sunglasses: http://www.oakleysunglassesstores.us.com/
Oakley Vault Sunglasses: http://www.oakleyvaultsunglasses.com/
Cheap Oakley Sunglasses: http://www.cheapoakleysunglasses.com.co/
Toms Outlet,Toms: http://www.tomsoutlet.in.net/
Abercrombie Outlet: http://www.abercrombieandfitchoutlets.com/
Abercrombie And Fitch: http://www.abercrombieandfitchoutlet.us.com/
Polo Ralph Lauren: http://www.polo-ralphlauren.us.com/
Ralph Lauren Outlet: http://www.ralphlaurenoutlets.us.com/
Valentino Shoes,Valentino: http://www.valentinoshoe.com/
Ray Ban Outlet,Ray Ban: http://www.raybansoutlet.us.com/
Coach Factory Outlet: http://www.coach-outletstores.us.com/
The North Face Outlet: http://www.thenorth-face.us.com/
Coach Factory Outlet: http://www.coachoutletonlinecoachfactory.us.com/
Kate Spade Handbags: http://www.katespadehandbag.us.com/
Coach Factory Outlet: http://www.coachfactory-outlet.us.org/
Coach Factory Outlet: http://www.coachfactoryoutletcoachoutletonline.com/
Coach Outlet Store Online: http://www.coachoutletstoresonline.com/
Coach Outlet,Coach Factory Outlet: http://www.outlet-coach.us.com/
Coach Factory Outlet: http://www.coachfactoryoutletonlines.us.com/
Kate Spade Outlet: http://www.katespades.us.com/
Giuseppe Zanotti: http://www.giuseppezanotti.us.com/
Sac chanel: http://www.saccuirmarron.com/
Michael Kors Outlet: http://www.outlet-michaelkors.us.com/
Ray Ban Sunglasses: http://www.raybanssunglasses.us.com/
Hollister Clothing Store: http://www.hollisteroutlet.us.com/
Abercrombie and Fitch: http://www.abercrombieoutlets.us.com/
Ralph Lauren Outlet: http://www.polosralphlauren.us.com/
Marc Jacobs handbags: http://www.jacobsmarcjacobs.com/
Marc By Marc Jacobs: http://www.marcjacobsmarcjacobs.com/
Marc Jacobs Outlet: http://www.marcjacobsoutletstores.com/
Chi Official Website: http://www.chiflatirons.us.com/

Add a Comment

Name

Email Address

1 + 1 = ?

Comment










iphone application development konrad group
android application development konrad group
windows phone 7 development konrad group