Focus lost event : Key Event « Event « JavaScript Tutorial






<html>
<head>
<title>Required Field</title>
<script type="text/javascript">
window.onload=setupEvents;
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>








15.7.Key Event
15.7.1.onkeydown key event handler
15.7.2.onkeyup key event handler
15.7.3.onkeypress key event handler
15.7.4.Display key event code in status bar (IE)
15.7.5.Use String.fromCharCode to convert key event code to key event char (IE)
15.7.6.Get key code
15.7.7.Get key char
15.7.8.Is Control pressed during the event
15.7.9.Is Alt pressed during the event
15.7.10.Is the Shift pressed during the event
15.7.11.Keystroke detector
15.7.12.Focus lost event