Commit 609efa9a authored by Raulin's avatar Raulin

formulaire aliment

parent b4341613
This diff is collapsed.
......@@ -9852,3 +9852,5 @@ form .row:first-child .floating-label-form-group {
background-color: #1a252f;
}
var selectedRow = null
function onFormSubmit() {
var formData = readFormData();
if (selectedRow == null)
insertNewRecord(formData);
else
updateRecord(formData);
resetForm();
}
function readFormData() {
var formData = {};
formData["aliment"] = document.getElementById("aliment").value;
formData["type"] = document.getElementById("type").value;
return formData;
}
function insertNewRecord(data) {
var table = document.getElementById("table_aliments").getElementsByTagName('tbody')[0];
var newRow = table.insertRow(table.length);
cell1 = newRow.insertCell(0);
cell1.innerHTML = data.aliment;
cell2 = newRow.insertCell(1);
cell2.innerHTML = data.type;
cell3 = newRow.insertCell(2);
cell3.innerHTML = `<a onClick="onEdit(this)">Edit</a>
<a onClick="onDelete(this)">Delete</a>`;
}
function resetForm() {
document.getElementById("aliment").value = "";
document.getElementById("type").value = "";
selectedRow = null;
}
function onEdit(td) {
selectedRow = td.parentElement.parentElement;
document.getElementById("aliment").value = selectedRow.cells[0].innerHTML;
document.getElementById("type").value = selectedRow.cells[1].innerHTML;
}
function updateRecord(formData) {
selectedRow.cells[0].innerHTML = formData.aliment;
selectedRow.cells[1].innerHTML = formData.type;
}
function onDelete(td) {
if (confirm("Supprimer l'élément ?")) {
row = td.parentElement.parentElement;
document.getElementById("table_aliments").deleteRow(row.rowIndex);
resetForm();
}
}
\ No newline at end of file
......@@ -16,7 +16,7 @@ if(isset($_GET['page'])){
<div class="container d-flex align-items-center flex-column">
<!-- Masthead Heading -->
<h2 class="masthead-heading text-uppercase mb-0"><?php echo $mymenu[$currentPageId][0] ?></h2>
<!-- <h2 class="masthead-heading text-uppercase mb-0"><?php echo $mymenu[$currentPageId][0] ?></h2> -->
<!-- Masthead Subheading -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment