Skip to content

Instantly share code, notes, and snippets.

@fixlr
Created May 6, 2009 18:20
Show Gist options
  • Save fixlr/107649 to your computer and use it in GitHub Desktop.
Save fixlr/107649 to your computer and use it in GitHub Desktop.
Clear login inputs on focus and restore their default values on blur.
function formInputs() {
return document.getElementById('loginform').getElementsByTagName('input');
}
function formClear() {
var inputs = formInputs();
for (i = 0; i<inputs.length; i++) {
if (inputs[i].type != 'submit' && inputs[i].value == inputs[i].defaultValue) {
inputs[i].value = '';
}
}
}
function formDefaults() {
var inputs = formInputs();
for (i = 0; i<inputs.length; i++){
if (inputs[i].type != 'submit' && inputs[i].value == '') {
inputs[i].value = inputs[i].defaultValue;
}
}
}
window.onload = function() {
var inputs = formInputs();
for (i = 0; i<inputs.length; i++) {
inputs.item(i).onfocus = function() {
formClear();
}
inputs.item(i).onblur = function() {
formDefaults();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment