Javascript DOM onblur Event via HTML Tag onblur function

Introduction

In JavaScript:

object.onblur = function(){
       myScript};

This example uses the HTML DOM to assign an "onblur" event to an input element.

Write something in the input field, and then click outside the field to lose focus (blur).

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="text" id="fname">
<p id="demo"></p>
<script>
document.getElementById("fname").onblur = function() {myFunction()};
function myFunction() {/*from   w  w  w . j  av a  2  s  . co  m*/
  document.getElementById("demo").innerHTML = "Input field lost focus.";
}
</script>

</body>
</html>
Bubbles:
Cancelable:
Event type:
Supported HTML tags:












No
No
FocusEvent
ALL HTML elements,
EXCEPT:
<base>,
<bdo>,
<br>,
<head>,
<html>,
<iframe>,
<meta>,
<param>,
<script>,
<style>, and
<title>



PreviousNext

Related