, UX, .
HTML5 placeholder value.
<input type="password" value="1234567">
Then, focusreplace with valuean empty string.
var inputs = document.getElementsByTagName('input'),
i = 0;
for (i = inputs.length; i--;) {
listenerForI(i);
}
function listenerForI(i) {
var input = inputs[i],
type = input.getAttribute('type'),
val = input.value;
if (type === 'password') {
input.addEventListener('focus', function() {
if (input.value === val) input.value = '';
});
input.addEventListener('blur', function() {
if (input.value === '') input.value = val;
});
}
}
I want to reiterate that I DO NOT recommend this approach, but it will do what you are looking for.
EDIT:
Please visit this page which will simulate functionality placeholderif it is not supported by your browser using jQuery: http://www.cssnewbie.com/cross-browser-support-for-html5-placeholder-text-in-forms/
source
share