javascript - Unable to validate user input - onkeyup event not firing -


I can not find any JavaScript errors, but the code does nothing ...

 < Code> function registerValidator (target, validator) {var element = document.getElementById (target); If (element) {var validationID = element.id + "_validationResult"; Var validation span = document. CreateElement ('span'); ValidationSpan.id = validationID; Element.parentNode.appendChild (validationSpan); Element.onkeyup = function () {var results = verifier (element); If (result.ok) {validationSpan.innerHTML = '& lt; Img src = "/ media / valid.gif" width = "12" />; '; } Else {validationSpan.innerHTML = '& lt; Img src = "/ media / invalid.gif" width = "12" />; '; If (result message) {Validation Spanner HTML + = '& lt; Br / & gt; + Result message; }}}; Warning (1); }} (Element.value.length & gt; = 4) {Results .ok = true;} and {result.ok = false; result. Message = "too small";} return result;}); Warning (2); }  

Two alerts (1 and 2) are being started correctly, but the 'valid' warning is never triggered. The function is used for the following element:

  & lt; Input type = "text" name = "user name" id = "user name" />  

I have tried to do this in Google Chrome, Firefox 3 and Internet Explorer 8.

Everything is working fine here.


You are currently using element.onkeyup which can be pasted from any other script. Try using

  (Element.addEventListener) element.addEventListener ("keyboard", validator, wrong); Else if (element.attachEvent) element.attachEvent ("onkeyup", validator);            

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -