Run JavaScript when an element loses focus

Teifion picture Teifion · Apr 20, 2009 · Viewed 172.3k times · Source

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);"/>

Answer

Canavar picture Canavar · Apr 20, 2009

How about onblur event :

<input type="text" name="name" value="value" onblur="alert(1);"/>