Refactor the way the element type (text or password) is checked