I am trying to change text in html using the DOM. I have a form with 2 radio buttons and a submit button. When submitted, it runs a JS function that should change text in HTML to reflect what answer they chose. However, whenever you click the submit button, it changes the text and then instantly flickers back to what the html shows. Why is it doing this? I've never seen this before. Here is the code...
function answerNext()
{
if(document.getElementById("question1").checked == true)
{
document.getElementById("qtext").innerText="You chose the first option";
}else if (document.getElementById("question2").checked == true)
{
documet.getElementById("qtext").innerText="You chose the second option";
}else
{
document.getElementById("qtext").innerText="You chose neither option";
document.getElementById("testdiv").innerHTML="<h1>You clicked next</h1>";
}
}
<!doctype html>
<html>
<head>
<title>Dog Personailty Quiz</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<script src="js/script.js"></script>
</head>
<body>
<h1>Is now a good time to get a dog?</h1>
<h2 id="qtext">Do you like to run a lot</h2>
<div id="testdiv"></div>
<form>
<input type="radio" id="question1" value="option1"> Option 1
<input type="radio" id="question2" value="option1"> Option 2
<input type="submit" value="Next" onclick="answerNext();">
</form>
</body>
</html>