Listen to Focus Lost event for input password in JavaScript

Description

The following code shows how to listen to Focus Lost event for input password.

Example


<html>
<head>
<script type="text/javascript">
window.onload=setupEvents;<!-- w  ww .  jav a 2  s .  c  om-->
function setupEvents(evnt) {
document.someForm.text2.onblur=checkRequired;

}

function checkRequired (evnt) {
evnt = evnt ? evnt : window.event;
var target = evnt.target ? evnt.target : evnt.srcElement;

var txtInput = target.value;
if (txtInput == null || txtInput == "") {
document.write("value is required in field");
}
}

</script>
</head>
<body>
<form name="someForm">
<input type="text" name="text1" /><br />
<input type="password" name="text2" /><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>

Click to view the demo

The code above generates the following result.

Listen to Focus Lost event for input password in JavaScript
Home »
  Javascript Tutorial »
    Event »
      Focus Event
Javascript Tutorial Focus Event
Add event handler for input text element on...
Add event listener to input text focus on e...
Listen to Focus Lost event for input passwo...