$(document).ready(function() { $("input[class*=_placeholder]").each(setupplaceholder); }); function setupplaceholder() { var classes = this.className.split(/\s+/); for (var i = 0, length = classes.length; i < length; i++) { if (classes[i].indexOf("_placeholder") > 0) { var tvalue = classes[i].replace("_placeholder", ""); $(this).removeClass(classes[i]); if (this.type.toLowerCase() == "password") { var nn = document.createElement("input"); nn.type = "text"; nn.name = "passplace"; nn.value = tvalue; var copystyle = $(this).attr("style"); $(nn).attr("style", copystyle); $(nn).addClass("_placeholder"); $(nn).one("click focus", null, clearpassholder); var newp = $(this).before(nn); $(this).addClass("hidden_elem"); } else { $(this).addClass("_placeholder"); this.value = tvalue; $(this).one("click focus", null, clearplaceholder); } break; } } if (this.value.toLowerCase() == "password") { $(this).click(clearpassholder); $(this).focus(clearpassholder); } } function clearplaceholder() { this.value = ""; $(this).removeClass("_placeholder"); } function clearpassholder() { $(this).addClass("hidden_elem"); $("input[type='password']", this.form).removeClass("hidden_elem"); $("input[type='password']", this.form).focus(); }