The first problem is preventing the page from loading and to do that, we pass the event object and use the preventDefault() method to stop the reload. Once that is done we grab the values of the input elements and use innerHTML to display it inside the
element with the help of the fancy template literals.
<button onClick="handleSubmit(event)">Submit</button>
function handleSubmit (e) {
e.preventDefault()
let name = document.getElementById("fname").value
let age = document.getElementById("age").value
let email = document.getElementById("email").value
document.getElementById("demo").innerHTML = `Name is : ${name} Age is: ${age}
and Email is : ${email}`;
}
I would not recommend implementing my answer as it is very unpolished and might cause problems in the long run, but I hope it helps.