formulaire pour remplir des ticket de panne
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.

58 lines
1.5 KiB

const check = document.getElementsByClassName('check');
const excla = document.getElementsByClassName('excla');
const entry = document.getElementsByClassName('entry');
document.getElementById("form").addEventListener('submit', function(e) {
e.preventDefault();
if (checkInputs() == true) {
var data = new FormData(this);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
alert('Votre ticket à bien été pris en compte');
} else if (this.readyState == 4) {
alert('une erreur est survenue...');
}
};
xhr.open('POST', 'cible/index.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';
}