postElement.innerHTML = `${post.topic} by ${post.name}`; postsContainer.appendChild(postElement); }); // Handle form submission document.getElementById('createpost').addEventListener('submit', (e) => { e.preventDefault(); const name = document.getElementById('name').value; const age = document.getElementById('age').value; const topic = document.getElementById('topic').value; const newPost = { name, age, topic }; posts.push(newPost); localStorage.setItem('posts', JSON.stringify(posts)); location.reload(); // Refresh the page to display the new post });