JavaScript for changing disabled to active button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
document.addEventListener('DOMContentLoaded', function(event) { | |
new ActiveForm().onEvent(event.target); | |
}, false); | |
})(); | |
function ActiveForm() { | |
this.submit = document.getElementById('submit'); | |
} | |
ActiveForm.prototype.init = function(target) { | |
this.onEvent(target); | |
}; | |
ActiveForm.prototype.onEvent = function(target) { | |
var self = this; | |
target.addEventListener('keydown', function(e) { | |
self.active(e.target); | |
},false); | |
target.addEventListener('keyup', function(e) { | |
self.active(e.target); | |
},false); | |
target.addEventListener('keypress', function(e) { | |
self.active(e.target); | |
},false); | |
target.addEventListener('change', function(e) { | |
self.active(e.target); | |
},false); | |
}; | |
ActiveForm.prototype.active = function(that) { | |
if (that.value.length > 0) { | |
this.removeAttr(); | |
} else { | |
this.AddAttr(); | |
} | |
}; | |
ActiveForm.prototype.removeAttr = function() { | |
this.submit.removeAttribute('disabled'); | |
}; | |
ActiveForm.prototype.AddAttr = function() { | |
this.submit.setAttribute('disabled', 'disabled'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment