The onblur
attribute is triggered
when the element lost focus.
None.
<element onblur="script">
All HTML elements, EXCEPT:
<base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, <title>
onblur |
Yes | Yes | Yes | Yes | Yes |
<!DOCTYPE html>
<html>
<body>
<!-- w ww .ja v a 2s . c o m-->
Enter your first name: <input type="text" name="fname" id="fname" onblur="myFunction()">
Enter your last name: <input type="text" name="lname" id="lname" onblur="myFunction()">
<script>
function myFunction() {
console.log("lost focus");
}
</script>
</body>
</html>
The following code shows how to listen to Focus Lost event for input password.
<html>
<head>
<script type="text/javascript">
function checkRequired() {<!-- www. j a v a2s . co m-->
document.write("value is required in field");
}
</script>
</head>
<body>
<form name="someForm">
<input type="text" name="text1" /><br />
<input type="password" name="text2" onblur='checkRequired();'/><br />
<input type="hidden" name="text3" value="hidden value" />
<textarea name="text4" cols=50 rows=10>The text area</textarea>
<input type="submit" value="Submit" />
</form>
</body>
</html>