Friday, January 9th, 2009
defaultValueActsAsHint
Thomas Fuchs has created defaultValueActsAsHint, an implementation of the Input Prompt pattern:
An often occuring UI pattern is “use the value of a textfield as hint what to input”. These fields all auto-clear when the user first focuses it (by clicking or tabbing it), and if nothing it entered, the hint will be shown once again once the user leaves it.
Because we decided to go this path for the “Quick entry” box we’re using for freckle time tracking, I dug out an older script I wrote and refreshed it a bit, and I present you defaultValueActsAsHint.
JAVASCRIPT:
$('element_id').defaultValueActsAsHint();This is all there’s to it, and the file to include is merely 18 lines of code. It works with textareas, too. Just specify whatever should be displayed as hint in the value attribute of the input (or as text within the textarea tag) and off you go. Define a ‘hint’ style if you like to show the text in gray, italics or whatever you fancy.
Check out the test sample that lives in his prototype_helpers library that also includes deferUntil.













jQuery users should check out ToggleVal. It’s currently at version 2.0.2, and has lots more options than just clearing/populating the inputs, such as conditional classes for styling, and clearing unchanged values on submit.
If you’re interested in a slightly more robust solution that doesn’t require you to manually call defaultValueActsAsHint() on each element you’d like to “hint”, you should check out my Ghostie project on Github (http://github.com/atnan/ghostie/tree/master), which allows you to add a CSS class of “ghostie” to any text/password field and it will automatically pull the value specified in the “title” attribute in as the default text. It also ensures that the default value is cleared if the form is submitted, and also adds a class of “ghostied” when the default value is populated so that you can style the default state easily.
In Jquery:
(function($){
$.fn.defaultValueActsAsHint = function(){
$(this).focus(function(){
if(this._default != this.value) return;
this.value = "";
}).removeClass('hint').blur(function(){
if(this.value != '') return;
this.value = this._default;
}).addClass('hint').get(0)._default = this.val();
};
})(jQuery);
For MooTools: http://www.clientcide.com/wiki/cnet-libraries/09-forms/05-overtext
An issue with using the
valueattribute is that it can be overwirtten when a user hits the back button after submitting the form, leaving your hint text as the value just submitted.I’ve published a jQuery implementation on GitHub that gets around this issue and the accessibility issue of not providing a
label– by default, it grabs the value from thelabeland moves thelabeloff-screen. You can override this behaviour if you want to use thevalueattribute, though.http://github.com/alexrabarts/jquery-clearinginput
I loved this implementation, but I agree further work would be nice to clear the values on form submission and supporting also select fields. Nice work,though.
It’s a flawed implementation, if you are halfway through a form and refresh the page then _default is set to the halfway value. Definately a bad bit of code! Kinda OK for freckle as the form is so small, but I’d reccomend against it.
Am I missing something, or is this virtually the same thing as this plugin – written 2 years ago:
http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
and:
http://www.alistapart.com/articles/makingcompactformsmoreaccessible
There’s another version that was written about 6-9 months ago too – but I can’t remember the link.
Have I missed the point – hasn’t this pattern been implemented time and time again?
Here’s an improved jQuery plugin that doesn’t use the value attribute because @oopstudio and @anewton’s concerns above. This version won’t change the value after a refresh since it uses a title attribute instead.
http://gist.github.com/46340
We’ve been doing this in schmedley on a bunch of our schmidgets and we’re using MooTools. After reading this article I was inspired to make a similar contribution – so, I made some quick edits to the code we’ve created and have posted an article with a MooTools class for this functionality on my site – http://dustincaruso.com/2009/01/defaultvalueactsashint/
It’s currently at version 2.0.2, and has lots more options than just clearing/populating the inputs, such as conditional classes for styling, and clearing unchanged values on submit.
Wow gold Wow gold buy wow gold buy wow gold cheap wow gold cheap wow gold cheapest wow gold cheapest wow gold buying wow gold buying wow gold sell wow gold sell wow gold wow gold for sale wow gold for sale wow gold sale wow gold sale wow buy gold
wow power leveling wow power leveling world of warcraf power leveling world of warcraf power leveling wow leveling wow leveling wow gold us wow gold us wow gold eu wow gold eu world of warcraft us world of warcraft us world of warcraft eu world of warcraft eu world of warcraft eu
wow co key wow co key wow co key wow buy gold wow cheap gold wow cheap gold wow gold for sale wow gold for sale world of warcraft gold world of warcraft gold wow accounts wow accounts wow power leveling wow power leveling world of warcraf power leveling
wow leveling world of warcraf power leveling wow leveling wow leveling wow co key wow co key wow accounts wow accounts cheap wow power leveling cheap wow power leveling buy wow power leveling buy wow power leveling buy wow power leveling
The Windows 7 key is a usually unique, alphanumeric code of any length required by many software programs during installation. Unique windows 7 product key help software manufacturers ensure that each copy of their software was legally purchased. Windows 7 Home key | Windows 7 Professional key | Windows 7 Ultimate key | Windows 7 Enterprise key | Windows 7 Home Premium key
The unique Windows 7 serial key entered for an operating system or a software program is typically stored in an encrypted format in the Windows Registry, making finding one very difficult without some help. The above linked guides should help find just about any Windows 7 CD key you may be looking for.Windows 7 Home product key | Windows 7 Professiona productl key | Windows 7 Ultimate product key
This Windows 7 product serial number, if it exists, is the generic Windows 7 Home product key that Microsoft allowed your PC builder to use when mass producing computers. In other words, everyone’s disc has the same product key. Your unique key for use when reinstalling Windows will be the one on the sticker on your computer. Windows 7 Enterprise key | Windows 7 Home Premium key
The xbox live points is the second video game console produced by Microsoft, and the successor to the Xbox. The xbox 360 live points competes with Sony’s xbox 360 live 1600 points and Nintendo’s Wii as part of the seventh generation of video game consoles.xbox live points card xbox 360 live points card
Some major features of the Xbox 360 are its integrated xbox 360 live 2000 points that allows players to compete online, download arcade games, game demos, trailers, TV shows and movies and its Windows Media Center multimedia capabilities. The xbox live 2000 points also offers region specific access to third-party media streaming services such as Netfilx in the USA or Sky TV and xbox 360 live 4000 points in the UK.
The xbox live 1600 points was officially unveiled on MTV on May 12, 2005, with detailed launch and game information divulged later that month at the Electronic Entertainment Expo (E3). The xbox live 4000 points sold out completely upon release in all regions except in Japan and, as of October 2009, nearly 34 million units have been sold worldwide. The xbox 360 live 3000 points is currently available in two configuraions—the “Arcade” and the “Elite”—and each has its own selection of accessories.
Buy Kamagra Earn Google M65 Jacket Viagra Cialis Cheap Kamagra Cheap Viagra Cheap Cialis Make Money on Google M65 Field Jacket Airline Dog Carrier Airline Dog Carriers Viagra Cialis Earn Google Airline Dog Carrier Airline Dog Carriers Airline Approved Dog Carriers ED Hardy Wholesale Copy DVD Software How to Send Fax 14k Yellow Gold Redneck Costume 14k Gold Heart Tandem Baby Stroller