To run JavaScript when an element loses focus, we set the onblur attribute to the JavaScript code we want to run.
For instance, we write
<input type="text" name="name" value="value" onblur="alert(1);" />
to set the onblur attribute to alert(1); to show an alert box when we move focus away from the input.