Why is the text flashing but not staying put?

<html><head>
<style>html {background: #171717}</style>
<center><br><br><br><br>
<form>
<p style="color: white;" >
Enter message:
</p>
<input type="text" title="Enter message..." id="comment">
<input type="submit" title="Send message" onclick="post()">
</form>
<div id="mess" style="color: white;">
</div>
<script>
message = document.getElementById("comment");
function post() {
document.getElementById("mess").innerHTML=(message.value);
}
</script>
</head>
<body>
</body>
</html>

When I run that it flashes the text on submit instead of putting it in for good, can anyone tell me why this happens? Everything works fine, and if I were to have it be an alert instead of inserting it into the html it works fine.

It’s because the button has the “submit” type, which actually changes the URL and causes the page to reload. You can just change the type to “button”.

*changes the URL if you used POST to pass variables, but the page will reload regardless.

1 Like

These tags are in the wrong place - they should come after the </style> tag

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.