Caner
Caner

Reputation: 59168

Text input focus loss event

I have the following page. I want to restore the input text if it has not been changed (when the focus is lost). How can I do this?


<html>
<head>
</head>
<body>

<script type="text/javascript">
function clearTextArea(object){
    object.value = "";
}
</script>

<input type="text" id="option" value="test" onfocus="clearTextArea(this);"></input>
</body>
</html>

Upvotes: 1

Views: 4982

Answers (2)

tcooc
tcooc

Reputation: 21209

Is there anything against using an

<input (...) onblur="this.value = 'test'">

listener?

(You can also do the same thing using a "placeholder" attribute if youre working with HTML5)

Upvotes: 2

Canavar
Canavar

Reputation: 48088

At your clearTextArea method take the current text in the text area and store in into a hidden field or a cookie. Then at on blur event, check if the value changed.

Upvotes: 1

Related Questions