I am displaying data on a page after submitting a form, in a div below the form whose visibility is initially set to hidden
using JavaScript I have set it to turn visible after button click
HTML:
<form action = "page2.php" method = "POST">
<select>
<option selected>Choose...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select>
<option selected>Choose...</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<button type="submit" name="btn1" onclick="showDiv()">Next</button>
</form>
<div style = "visibility:hidden" id = "aftersubmit">
<p>Data</p>
...
</div>
JS:
function showDiv() {
document.getElementById("aftersubmit").style.visibility = 'visible';
}
I want the div to be visible after I click the submit button on the form, but since the form is being posted, the page refreshes and the style goes back to hidden.