javascript - Onblur returns wrong data -


my form check not work. if leave alias field empty returns name field filled.

var alias = document.getelementbyid("alias"); var name = document.getelementbyid("name"); var status = '';  function checkit() {     if (alias.value != '') {         document.getelementbyid("alias").style.bordercolor = "#3c763d";         return true;     } else {         document.getelementbyid("alias").style.bordercolor = "#a94442";         status = false;     }     if (name.value != '') {         document.getelementbyid("name").style.bordercolor = "#3c763d";         return true;     } else {         document.getelementbyid("name").style.bordercolor = "#a94442";         status = false;     } }  name.onblur=checkit; alias.onblur=checkit; 

try this, should use current object this instead of global variable when eventing firing

var alias = document.getelementbyid("alias"); var name = document.getelementbyid("name"); var status = '';  function checkit() { if (this.value != '') {     this.style.bordercolor = "#3c763d";     status = true; } else {     this.style.bordercolor = "#a94442";     status = false; } }  name.onblur=checkit; alias.onblur=checkit; 

jsfiddle demo


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -