Form Field Default Values with jQuery

2014-09-21 • Plugins, Snippets • Views: 1691

Form Field Default Values with jQuery


<!DOCTYPE html>
<script type="text/javascript">
$(document).ready(function() {
$(‘.someClass’).each(function() {
var $this = $(this);
var defaultVal = $this.attr(‘title’);

$this.focus(function() {
if ($this.val() === defaultVal) {

$this.blur(function() {
if ($this.val().length === 0) {
input {
<input class="someClass" type="text" title="Name" value="Name" />
<input class="someClass" type="text" title="Email Address" value="Email Address" />
<input class="someClass" type="text" title="Default Value Here" value="Insert form refill here" />


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>