Simplified by handling onchange event instead of mouse/touch events