To prevent the form from submitting to the server without hiding it, you have a couple of options. You can either use Ajax to submit the form in the background, target an iframe or open a new tab.
If the form submission results in loading the same page, you can choose to hide the form on the server side or store a directive in localStorage instructing the page not to display the form.
I would strongly advise against using the onclick event for a submit button; instead, utilize the submit event for better control and functionality.
document.getElementById("myForm").addEventListener("submit", function(e) {
e.preventDefault(); // To prevent form submission
document.getElementById("small-form").classList.add("hide");
// Perform other actions such as AJAX requests here
})
.hide { display: none; }
<div id="small-form">
<form id="myForm">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<input type="submit" value="Submit">
</form>
</div>