I try to make a On and Off button in html and but when I put the tag input inside the Form doesn't work it stay on off doesn't switch to On
function onoff() {
currentvalue = document.getElementById('onoff').value;
if (currentvalue === "Off") {
document.getElementById("onoff").value = "On";
} else {
document.getElementById("onoff").value = "Off";
}
}
<form action="" method="post">
<input type="button" value="Off" id="onoff" onclick="onoff();" class="button button2">
</form>