Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Listen for changes on the entire window
window.addEventListener('change', function (event) {
// matches polyfill
if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.msMatchesSelector ||Element.prototype.webkitMatchesSelector;
}
if (event.target.matches('[type=checkbox]')) {
const showOnePwd = document.querySelector('#password');
const nodeForms = Array.prototype.slice.call(document.querySelectorAll('form'));
const showMultiplePwd = Array.prototype.slice.call(nodeForms[1].querySelectorAll('[type=password]'));
const checkbox1 = nodeForms[0].querySelector('[type=checkbox]');
const checkbox2 = nodeForms[1].querySelector('[type=checkbox]');
// console.log(showOnePwd);
// console.log(nodeForms);
// console.log(showMultiplePwd);
// console.log(checkbox1.checked);
// console.log(checkbox2);
if (checkbox1.checked) {
showOnePwd.type = 'text';
} else {
showOnePwd.type = 'password';
console.log('You have no password written');
}
if (checkbox2.checked) {
showMultiplePwd.forEach(function(eachNode, i){
eachNode.setAttribute('type', 'text');
});
} else {
showMultiplePwd.forEach(function(eachNode, i){
eachNode.setAttribute('type', 'password');
});
}
}
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.