Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach event to clear icon in IE10 textbox

In IE10 a small X icon appears in the textbox to clear the input text. How can an event be attached to that action (=clicking on that X and clearing the input)?

like image 628
ABC Avatar asked Feb 05 '13 04:02

ABC


1 Answers

It seems there's not an exact event for this (onchange is not suitable). However, you can use oninput and check, if the value of the input is empty:

document.getElementById('input_ID').addEventListener('input', function () {
    if (this.value === '') {
        alert('No value');
    }
}, false);

This event is triggered also, if user clears the input with BACKSPACE or DELETE, or cuts the content to the clipboard. oninput works at least in Chrome, FF, IE10 and Opera.

like image 152
Teemu Avatar answered Sep 23 '22 10:09

Teemu