This piece of code makes form fields more intelligent and usable. It clears the field on focus and if nothing is filled-in, it puts back the default value. There is a single line function MooTools
for this, but I used jQuery elsewhere on the web, so I needed jQuery solution. But couldn’t find any good one, so I put together my own.
The form can be seen in action at http://www.fofrem.info/objednat.html
Usage:
Just put the default text into alt attribute of the text field, like this:
For some reason, I couldn’t make it work by using value attribute. The if($(this).val()==$(this).attr("value")) part doesn’t work. Anyone knows why?
The script will do the rest. It is pretty obvious from the code how it works, even if you know little about jQuery.
Please don’t hesitate to leave a comment if you need more details. Enjoy!