You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.7 KiB
63 lines
1.7 KiB
3 years ago
|
const button = document.getElementById('submit');
|
||
|
const page = document.getElementById('page');
|
||
|
|
||
|
const check = document.getElementsByClassName('check');
|
||
|
const excla = document.getElementsByClassName('excla');
|
||
|
const entry = document.getElementsByClassName('entry');
|
||
|
const help = document.getElementsByClassName('help');
|
||
|
|
||
|
|
||
|
document.getElementById("form").addEventListener('submit', function(e) {
|
||
|
e.preventDefault();
|
||
|
if (checkInputs() == true) {
|
||
|
console.log('check');
|
||
|
var data = new FormData(this);
|
||
|
|
||
|
var xhr = new XMLHttpRequest();
|
||
|
|
||
|
xhr.onreadystatechange = function() {
|
||
|
if (this.readyState == 4 && this.status == 200) {
|
||
|
console.log(this.response);
|
||
|
} else if (this.readyState == 4) {
|
||
|
alert('uhe erreur est survenue...');
|
||
|
}
|
||
|
};
|
||
|
xhr.open('POST', 'cible.php', true);
|
||
|
xhr.send(data);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
function displayHelp(id) {
|
||
|
id.style.display = 'block';
|
||
|
}
|
||
|
|
||
|
function hideHelp(id) {
|
||
|
id.style.display = 'none';
|
||
|
}
|
||
|
|
||
|
function checkInputs() {
|
||
|
let success = true;
|
||
|
for (let i=0; i < (entry.length - 1) ; i++) {
|
||
|
if (entry[i].value == '') {
|
||
|
setError(i);
|
||
|
success = false;
|
||
|
}
|
||
|
else {
|
||
|
setSuccess(i);
|
||
|
}
|
||
|
}
|
||
|
return success;
|
||
|
}
|
||
|
|
||
|
function setError(indice) {
|
||
|
check[indice].style.display = 'none';
|
||
|
excla[indice].style.display = 'block';
|
||
|
document.getElementsByTagName('small')[indice].style.display = 'block';
|
||
|
}
|
||
|
|
||
|
function setSuccess(indice) {
|
||
|
check[indice].style.display = 'block';
|
||
|
excla[indice].style.display = 'none';
|
||
|
document.getElementsByTagName('small')[indice].style.display = 'none';
|
||
|
}
|