I need to check with Javascript (not jQuery) if the given input element is writable by the user using the keyboard.
I'd like to exclude checkboxes, radios, buttons, resets, submits, image and so on.
Is there a simple way to do it without list all the input types?
This is my current code now:
if (element.getAttribute === undefined) {
return false;
}
var eTag = element.tagName;
var eType = element.getAttribute('type');
var isTextInput = (eTag === 'INPUT' || eTag === 'TEXTAREA') && ( eType !== null || eType === 'text' || eType === 'password');
var isEnabledInput = element.disabled === false && element.readOnly === false;
var isContentEditable = ( element.contentEditable && element.contentEditable === true );
// stop for enabled text inputs, selects and contentEditable areas
return (isTextInput && isEnabledInput) || eType === 'SELECT' || isContentEditable;
Logically the && ( eType !== null || eType === 'text' || eType === 'password'); is not enough to check them all.
type = text). It will returnfalseif the input is of typenumber