function Slider(id) { let td = document.getElementsByClassName(id); let is_checked; if (td[12].querySelector('input').checked == true) { is_checked = 1; } else { is_checked = 0; } let xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if (is_checked == 1) { td[11].querySelector('img').src = "../img/check.png"; } else { td[11].querySelector('img').src = "../img/excla.png"; } } }; xhr.open('POST', 'cible/slider.php', true); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.send("is_checked=" + encodeURI(is_checked) + "&id=" + encodeURI(td[0].textContent)); } function Edit(clas) { let obj = document.getElementsByClassName(clas); let data = new FormData(); if (obj[13].querySelector('input').value == 'edit') { for (let i=1; i< 11; i++) { obj[i].innerHTML = ''; } obj[13].querySelector('input').value = 'ok'; } else { let value = new Value(obj); let xhr = new XMLHttpRequest(); data.append('value', JSON.stringify(value)); console.log(data); xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { console.log(this.response); for (let i=1; i<11; i++) { obj[i].innerHTML = this.response[i]; } obj[13].querySelector('input').value = 'edit'; } }; xhr.open('POST', 'cible/edit.php', true); xhr.responseType = 'json'; xhr.send(data); } } function Value(list) { this.id = list[0].textContent; this.dates = list[1].querySelector('input').value; this.details = list[2].querySelector('input').value; this.lieu = list[3].querySelector('input').value; this.salle = list[4].querySelector('input').value; this.pos = list[5].querySelector('input').value; this.materiel = list[6].querySelector('input').value; this.marque = list[7].querySelector('input').value; this.model = list[8].querySelector('input').value; this.nserie = list[9].querySelector('input').value; this.demandeur = list[10].querySelector('input').value; if (list[11].querySelector('img').src == '../img/check.png') { this.traitement = 1; } else { this.traitement = 0; } }