Skip to content

Instantly share code, notes, and snippets.

@bathtimefish
Created December 1, 2018 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bathtimefish/6c8c8f1585fac1faeec44841d69b66b7 to your computer and use it in GitHub Desktop.
Save bathtimefish/6c8c8f1585fac1faeec44841d69b66b7 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Radio button example</title>
</head>
<body>
<form id="form1">
<div>
<input type="radio" name="target" value="1" onchange="handler()">
<span>1</span>
</div>
<div>
<input type="radio" name="target" value="2" onchange="handler()">
<span>2</span>
</div>
<div>
<input type="radio" name="target" value="3" onchange="handler()">
<span>3</span>
</div>
</form>
<hr>
<br>
<b>Result: </b>
<span id="result"></span>
<script>
var handler = function() {
var elForm = document.querySelector('#form1');
var elRadios = elForm.target;
var value = elRadios.value;
document.querySelector('#result').innerHTML = value;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment