I am following a beginner class in html. Through javascript I am trying to modify a form button aspect when the form is submitted, but that modification reverts right away. It looks like the DOM or the form gets reset, but I don't know how to work around that.
function validateQuestion1(radio){
document.getElementById("valider1").style.background='green';
myAnswer = false;
for (var i=0;i<radio.length;i++) {
if ((radio[i].checked) && (radio[i].value=="1")) {
myAnswer=true;
}
}
}
<body>
<form name="question1">
<legend>La première balise présente dans un fichier html doit être:</legend>
<input type="radio" id="choix1" name="Q1" value="0">
<label for="head" id="head1">head</label>
<input type="radio" id="choix2" name="Q1" value="0">
<label for="body" id="head2">body</label>
<input type="radio" id="choix3" name="Q1" value="1">
<label for="!DOCTYPE" id="head3">!DOCTYPE</label>
<input type="radio" id="choix4" name="Q1" value="0">
<label for="html" id="head4">html</label>
<button onclick="validateQuestion1(document.forms.question1.Q1)" id="valider1">Valider</button>
</form>
</body>