When making fancy web 2.0 javascript form validations, sometimes you may want to validate a html textfield right after the data was entered. What you need is to cacth the ‘textfield lose focus’ event‘, that is when a user enters some data into the textfield and then either clicks outside the field or ‘tabs’ to the next field.
The JavaScript lose focus event is actually called onBlur, and is suppoerted by the following HTML tags:
<a>, <acronym>, <address>, <area>, <b>, <bdo>, <big>, <blockquote>, <button>, <caption>, <cite>, <dd>, <del>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, <form>, <frame>, <frameset>, <h1> to <h6>, <hr>, <i>, <iframe>, <img>, <input>, <ins>, <kbd>, <label>, <legend>, <li>, <object>, <ol>, <p>, <pre>, <q>, <samp>, <select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <ul>, <var>
and the following JavaScript objects:
button, checkbox, fileUpload, layer, frame, password, radio, reset, submit, text, textarea, window
Usage example:
<html>
<head>
<script type="text/javascript">
function upperCase()
{
var x=document.getElementById("fname").value;
document.getElementById("fname").value=x.toUpperCase();
}
</script>
</head>
<body>
Enter your name:
<input type="text" id="fname" onblur="upperCase()">
</body>
</html>
RSS feed for comments on this post · TrackBack URI
Leave a reply