Skip to content

Instantly share code, notes, and snippets.

@gamafranco
Created July 16, 2010 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamafranco/478318 to your computer and use it in GitHub Desktop.
Save gamafranco/478318 to your computer and use it in GitHub Desktop.
//--script for labels inside forms--
function clearFieldsBehavior(){
clearFields = jQuery(".clearField");
clearFields.keydown(function() {
inputLabel = jQuery("label[for=" + this.id + "]")
if (this.value.length == 0) {
inputLabel.show();
} else {
inputLabel.hide();
}
});
clearFields.keyup(function() {
inputLabel = jQuery("label[for=" + this.id + "]")
if (this.value.length == 0) {
inputLabel.show();
} else {
inputLabel.hide();
}
});
clearFields.blur(function() {
inputLabel = jQuery("label[for=" + this.id + "]")
if (this.value.length != 0) {
inputLabel.hide();
} else {
inputLabel.show();
}
});
clearFields.each(function(key, value) {
inputLabel = jQuery("label[for=" + this.id + "]")
if (this.value.length != 0) {
inputLabel.hide();
} else {
inputLabel.show();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment