Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//--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