0% found this document useful (0 votes)
32 views1 page

Json

The document is a JavaScript code snippet that initializes a form and a table to manage user registrations. It retrieves existing registrations from local storage, allows users to submit new registrations, and updates the table dynamically. The table displays three fields from each registration and resets the form after submission.

Uploaded by

moonpeach201008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views1 page

Json

The document is a JavaScript code snippet that initializes a form and a table to manage user registrations. It retrieves existing registrations from local storage, allows users to submit new registrations, and updates the table dynamically. The table displays three fields from each registration and resets the form after submission.

Uploaded by

moonpeach201008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

document.

addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('cadastroForm');
const tableBody = document.querySelector('#cadastrosTable tbody');
let cadastros = JSON.parse(localStorage.getItem('cadastros')) || [];

const renderTable = () => {


tableBody.innerHTML = '';
cadastros.forEach((cadastro, index) => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${cadastro.campo1}</td>
<td>${cadastro.campo2}</td>
<td>${cadastro.campo3}</td>
`;
tableBody.appendChild(row);
});
};

form.addEventListener('submit', (event) => {


event.preventDefault();
const cadastro = {
campo1: form.campo1.value,
campo2: form.campo2.value,
campo3: form.campo3.value
};
cadastros.push(cadastro);
localStorage.setItem('cadastros', JSON.stringify(cadastros));
renderTable();
form.reset();
});

renderTable();
});

You might also like