How can I check if a value is changed on blur event?

pencilCake picture pencilCake · Feb 25, 2010 · Viewed 34.1k times · Source

Basically I need to check if the value is changed in a textbox on the 'blur' event so that if the value is not changed, I want to cancel the blur event.

If it possible to check it the value is changed by user on the blur event of an input HTML element?

Answer

Pekka picture Pekka · Feb 25, 2010

I don't think there is a native way to do this. What I would do is, add a function to the focus event that saves the current value into a variable attached to the element (element.oldValue = element.value). You could check against that value onBLur.