SomeStudent SomeStudent - 1 year ago 86
HTML Question

how to handle onfocusout, html validation

In my code I have the following line of code:

<input type="text" name="fname" id="first" onfocusout="firstNameHandler()">

when I run it through the HTML validator (required as it is for academic purposes), it flags that as a problem. Here's my problem, I require onfocusout as we have text input fields and when you write your name, such as for example, john, it turns it into John. This should only happen when you are no longer in focus of said text input field.

Therefore, what is the proper way to handle this?

Answer Source

Yes, onfocusout is not portable and does not work in Firefox. For Internet Explorer:

function isIE () { var myNav = navigator.userAgent.toLowerCase(); return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false; }

Then, since IE 9 and later support onblur, but IE 8 and earlier don't:

if (isIE () && isIE () < 9) { // is IE version less than 9 // insert code to tell the user that they are using a version of // internet explorer that doesn't work with your page // and is outdated.

else { // is IE 9 and later or not IE // This means that this will (probably) work // unless the user is using an extremely outdated browser // or one that doesn't support JavaScript.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download