Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
JavaScript for changing disabled to active button
(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