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 “[email protected]”. 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.

  1. <input placeholder="Enter a username…" type="text">
  2. <input placeholder="…and a password" type="password">

Then initiate Default Value on those elements.

  1. $(' [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.

Change log
VersionChanges
1.4.2Fixed detection for native placeholder support and added two more attributes – row and cols – to the clone. (Thanks to marcus)
1.4.1Fixed an issue regarding detection for native placeholder support.
1.4Now uses the HTML5 attribute placeholder instead of rel
1.3.1Fixed Lazy compatibility (Thanks Anders Adlén)
1.3Refactored (Thanks Kristofer Karlsson)
1.2Fixed an ‘addClass’ is not a function error (Thanks pentarim)
1.1Refactored. Default values are now removed when closest form is submitted. Fixed tabindex issue. (Thanks a lot to Paul Elliott)

3 days ago

Wow! I don’t even remember anymore how I managed before this new awesome boilerstrap. http://t.co/bWzwqVf2

3 days ago

If you like coding and competing and want to see Stockholm at its best; Checkout Escape from /dev/null – DICE edition. http://t.co/0SapzZxz

4 days ago

Going where none has gone before and pushing the boundaries of what has been called done. Mine, @soe, @tussetor #SthlmStartupHack app ≈Done