Skip to content

Instantly share code, notes, and snippets.

@gmelodie
Created January 30, 2019 12:55
Show Gist options
  • Save gmelodie/bd1a99d2c608d2489c8831e4b366ffd2 to your computer and use it in GitHub Desktop.
Save gmelodie/bd1a99d2c608d2489c8831e4b366ffd2 to your computer and use it in GitHub Desktop.
Version 2 of tic-tac-toe, fixing hiding problems
<html>
<script type="text/javascript">
function getSelectedButton(form, name) {
let radios = form.elements[name];
for (button in radios) {
if (radios[button].checked) {
return radios[button];
}
}
}
function computePlay() {
let selected = getSelectedButton(document.getElementById('board'), 'play');
selected.style.display = 'none';
}
</script>
<h1> Tic-tac-toe </h1>
<form id='board'>
<input type="radio" name="play" onclick="computePlay()" id="11">
<input type="radio" name="play" onclick="computePlay()" id="12">
<input type="radio" name="play" onclick="computePlay()" id="13">
<br>
<input type="radio" name="play" onclick="computePlay()" id="21">
<input type="radio" name="play" onclick="computePlay()" id="22">
<input type="radio" name="play" onclick="computePlay()" id="23">
<br>
<input type="radio" name="play" onclick="computePlay()" id="31">
<input type="radio" name="play" onclick="computePlay()" id="32">
<input type="radio" name="play" onclick="computePlay()" id="33">
<br>
</form>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment