Im doing a automatic form validation. But i got function in function and helping argument from for(),and on the first function x=0 in next,deeper function x is undefined `
var check = [ /[A-Z][a-z]+/g,
/[A-Z][a-z]+/g];
function input() {
form = document.getElementById('form');
for(x=0;x<6;x++) { //Here is my x,and x=0
form[x].onchange = function() { // form[x]=form[0]
content = this.value;
(check[x].test(content))? alert('yes') : alert('no'); //here x is undefined :(
};
};
}
window.onload = function loaded() {
input();
};
`
Uncaught TypeError: Cannot read property 'test' of undefined at HTMLInputElement.form.(anonymous function).onchange