I have a standard HTML input that I want to run JavaScript code when it loses focus. Sadly my Google searches did not reveal how to do this.
To make it clear, I'm looking for a way to do this:
<input type="text" name="name" value="value" onlosefocus="alert(1);"/>
This question is related to
javascript
html
javascript-events
You want to use the onblur event.
<input type="text" name="name" value="value" onblur="alert(1);"/>
From w3schools.com: Made compatible with Firefox Sept, 2016
<input type="text" onfocusout="myFunction()">
You're looking for the onblur
event. Look here, for more details.
onblur
is the opposite of onfocus
.
Source: Stackoverflow.com