I am playing with the form validation using javascript. so when ever i use (this) keyword in prototype method (Validator) the console is giving me an error that is in this picture Error from chrome. so help me
function Validation(id, event, target, regex) {
this.id = id;
this.event = event;
this.target = target;
this.regex = regex;
}
Validation.prototype.Validator = function() {
var result = this.regex.exec(this.target.value);
if(result && this.target != null) {
alert("you did it");
}
else {
alert('no you didn\'t');
}
};
var object1 = new Validation(document.getElementById('btn'), eventer, document.getElementById('box'), /\w/);
var eventer = object1.id.addEventListener("click", object1.Validator);
var object2 = new Validation(document.getElementById('btn'),
eventer2,document.getElementById('passbox'), /\d/);
var eventer2 = object2.id.addEventListener("click", object2.Validator);
<style>
.label {
display: inline-block;
margin-top: 5px;
}
#box {
margin-left: 5px;
}
#passbox {
margin-left: 8px;
}
</style>
<!doctype html>
<html>
<head>
<title>playing with forms</title>
</head>
<body>
<div>
<div><span class="label">Username: </span><input type="text" id="box">
</div>
<div><span class="label">Password: </span><input type="text"
id="passbox"></div>
</div>
<input type="submit" id="btn" value="clickme"/>
</body>
</html>