Once the form is submitted, the page is reloaded without the "Test" message.
Since you want the "Test" message to persist after form submission, I suggest some server-side code to display it conditionally (if the form has been submitted).
Using PHP, it would go something like this:
<?php
// determine if the form was submitted
$submitted=isset($_POST['submitted']) ? true : false;
?>
<form method="post" onsubmit="myFunction();" >
<input type="submit" value="submit" name="submitted" />
</form>
<!-- echo message if form was submitted -->
<div id="div6"><?php echo $submitted ? "Test" : ""; ?></div>
<script>
function myFunction() {
document.getElementById("div6").innerHTML="Test";
}
</script>
Alternatively, you could submit the form using AJAX so that the page does not reload.
But that's a different story.