Default Value
Defualt Value is a fallback for the HTML5 placeholder attribute. It sets a default value on your input elements if they are empty. The default value disappears if the input gain focus or the user types something in it, even in browsers without support for the placeholder attribute.
The placeholder attribute is perfect for label values like “Search here…”, “Username” or example values like “john@doe.com”. The placeholder attribute and Default Value works with text-, password-inputs and textareas.
How to use Defaultvalue
Use the HTML5 placeholder attribute is you normally would.
- <input placeholder="Enter a username…" type="text">
- <input placeholder="…and a password" type="password">
Then initiate Default Value on those elements.
- $(' [placeholder] ').defaultValue();
Empty input fields has the class name ‘empty’
When the default value is shown the class name ‘empty’ is added to the field. Take a look at the demo and see how the default values differs from the user created values.
Default Value manipulates the DOM
Since you can’t change the type of an input field in Internet Explorer, Defaultvalue creates a clone of your password field but with the type text instead.
| Version | Changes |
|---|---|
| 1.4.2 | Fixed detection for native placeholder support and added two more attributes – row and cols – to the clone. (Thanks to marcus) |
| 1.4.1 | Fixed an issue regarding detection for native placeholder support. |
| 1.4 | Now uses the HTML5 attribute placeholder instead of rel |
| 1.3.1 | Fixed Lazy compatibility (Thanks Anders Adlén) |
| 1.3 | Refactored (Thanks Kristofer Karlsson) |
| 1.2 | Fixed an ‘addClass’ is not a function error (Thanks pentarim) |
| 1.1 | Refactored. Default values are now removed when closest form is submitted. Fixed tabindex issue. (Thanks a lot to Paul Elliott) |
3 days ago
Twitter Bootstrap 2.0 is here. By nerds, for nerds. Cross everything. http://t.co/J4cFxGlb A neat looking front-end toolkit.
5 days ago
“CoffeeScript is Beautiful; Don’t Use It” My thoughts exactly. Thank you @ryanflorence! http://t.co/4bTAAIqE
5 days ago
“CoffeeScript is Beautiful; Don’t Use It” My thoughts exactly. Thank you @ryanflorence! http://t.co/4bTAAIqE
9 days ago
Looking for a solid way to do application versioning? Look no further. http://t.co/OMYJ2xzF Semantic Versioning guidelines are nifty!
11 days ago
The impossible is possible! http://t.co/Y4whjPIT Girl sneezes with open eyes.
15 days ago
On Amazon: Bad reviews are better for product sales than no reviews. (via @ronnestam )
15 days ago
There are only 180k Twitter users in Sweden, but ~75% of Sweden’s journalists use Twitter. (via @ronnestam )