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.

  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)

651 days ago

Read one article about glass; read this one about Corning, Corning’s Gorilla Glass, Apple and the future. http://t.co/xakeeQzU (via @VirUZI)

652 days ago

I just bought CHTEMELE; a boardgame about HTML5 for 2 – 5 players. http://t.co/kbpQLivu

654 days ago

A normal male ejaculation is equivalent of 16 terabyte of information. http://t.co/tkLndAwg

656 days ago

We are 18, we have no work, we don’t study, we are Anonymous. -We know. http://t.co/NHPa7gjR

656 days ago

We are 18, we have no work, we don’t study, we are Anonymous. -We know. http://t.co/NHPa7gjR

657 days ago

Anonymous plan to DDoS the Central Bank of Sweden’s website, in the middle of the Swedish night, to hurt our economy. Have fun, Goodnight :)

657 days ago

Book trailer for Instant: The story of Polaroid [the Apple of the 60s]. http://t.co/y4srSGmP