1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
var check_onkeyup = {};
var check_onblur = {};
var checked = {};
checked['email'] = false;
checked['password'] = false;
var button_enregistrer = document.getElementById('button_enregistrer');
button_enregistrer.disabled = 'disabled';
// retourne le "tooltip" le plus proche de l'élément <input> utlisé
function getTooltip(element) {
while (element = element.nextSibling) {
if (element.className === 'tooltip') {
return element;
}
}
return false;
}
check_onkeyup['email'] = function () {
var email = document.getElementById('email'),
tooltipStyle = getTooltip(email).style;
if (email.value.length > 0) {
if (/^[a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,6}$/.test(email.value)) {
email.className = 'correct';
tooltipStyle.display = 'none';
checked['email'] = true;
} else {
email.className = 'in_progress';
tooltipStyle.display = 'inline-block';
checked['email'] = false;
}
}
}
check_onblur['email'] = function () {
var email = document.getElementById('email'),
tooltipStyle = getTooltip(email).style;
if (email.value.length == 0) {
email.className = 'none';
tooltipStyle.display = 'inline-block';
checked['email'] = false;
} else if (/^[a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,6}$/.test(email.value)) {
email.className = 'correct';
tooltipStyle.display = 'none';
checked['email'] = true;
} else {
email.className = 'incorrect';
tooltipStyle.display = 'inline-block';
checked['email'] = false;
}
}
check_onkeyup['password'] = function () {
var password = document.getElementById('password'),
tooltipStyle = getTooltip(password).style;
if (password.value.length > 0) {
if (password.value.length >= 4) {
password.className = 'correct';
tooltipStyle.display = 'none';
checked['password'] = true;
} else {
password.className = 'in_progress';
tooltipStyle.display = 'inline-block';
checked['password'] = false;
}
}
}
check_onblur['password'] = function () {
var password = document.getElementById('password'),
tooltipStyle = getTooltip(password).style;
if (password.value.length == 0) {
password.className = 'none';
tooltipStyle.display = 'inline-block';
checked['password'] = false;
} else if (password.value.length < 4) {
password.className = 'incorrect';
tooltipStyle.display = 'inline-block';
checked['password'] = false;
} else {
password.className = 'correct';
tooltipStyle.display = 'none';
checked['password'] = true;
}
}
function check_2() {
var count = 0;
var button_enregistrer = document.getElementById('button_enregistrer');
for (var i in checked) {
if (checked[i] == true) {
count++;
}
else {
count--;
}
}
if (count == 2) {
button_enregistrer.disabled = '';
}
else {
button_enregistrer.disabled = 'disabled';
}
}
var inputs = document.getElementsByTagName('input'),
inputsLength = inputs.length;
for (var i = 0 ; i < inputsLength ; i++) {
inputs[i].onkeyup = function() {
check_onkeyup[this.id](this.id);
check_2();
};
inputs[i].onblur = function() {
check_onblur[this.id](this.id);
check_2();
};
} |