const table_ticket = document.getElementsByClassName('ticket'); const table_title = document.getElementsByClassName('table-title'); var id_displayed; document.getElementById('form').addEventListener('submit', function(e) { e.preventDefault(); let data = new FormData(this); let xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if (this.response != false) { id_displayed = data.get('id'); for (let i=0; i < 12; i++) { table_ticket[i].textContent = this.response[i]; } document.getElementById('table-search').style.display = 'block'; } else { alert("Ce ticket n'existe pas"); } } else if (this.readyState == 4) { alert('uhe erreur est survenue...'); } }; xhr.open('POST', 'cible/search.php', true); xhr.responseType = 'json'; xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.send("id=" + encodeURI(data.get('id'))); }); 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) { td[11].textContent = this.response; } }; xhr.open('POST', 'cible/index.php', true); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.send("is_checked=" + encodeURI(is_checked) + "&id=" + encodeURI(id_displayed)); } function Edit(clas) { let obj = document.getElementsByClassName(clas); let data = new FormData(); if (obj[13].querySelector('input').value == 'edit') { for (let i=1; i< 12; 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<12; 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; this.traitement = list[11].querySelector('input').value; }