My Ride
Started: Thursday 20th June 2013 7:06am
Distance: 13.36km
Duration: 00:30:30
Rest Time: 00:13:55
Climb: 100m
Max Speed: 56.52kmph
Average Speed: 26.29kmphInstagrams
-
Recent Posts
Recent Comments
Archives
- February 2013
- December 2012
- September 2012
- July 2012
- January 2012
- September 2011
- August 2011
- February 2011
- January 2011
- November 2010
- October 2010
- August 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
Categories
Meta
jQuery – Clear Default Input Values Once
April 30, 2010,
6,531 views
I like to have default values in my text input fields. However it is an annoying user experience to have to manually clear the value out and then enter in the value. Instead I thought I would write a simple script that would work site wide to clear out the default values. You of course will need your jquery included:
Following some brilliant comments on this there is a much quicker method:
$('input[type=text]').one('focus', function(){
$(this).attr('value', '');
});
However the original code I came up with is as follows:
$(function(){
$('input[type=text]').focus(function(){
if (!this.clicked) {
$(this).attr('value', '');
this.clicked = true;
}
});
});
This will clear the fields out only once. So if the user enters a value, then focuses back on the field, their values won’t be cleared. So if they needed to edit a single letter, then their entire entry won’t be wiped. If you have any hints feel free to comment






3 Comments
Instead of setting the clicked property you could just use the .one() method. http://api.jquery.com/one/
It’s great for uses such as this…
Hi, I’m very interested in Linux but Im a Super Newbie and I’m having trouble deciding on the right distribution for me (Havent you heard this a million times?) anyway here is my problem, I need a distribution that can switch between reading and writing in English and Japanese (Japanese Language Support) with out restarting the operating system.
Great snippet, but how would you re-instate the default value on focusout()?