Skip to content

Instantly share code, notes, and snippets.

@Zillionx
Last active September 11, 2015 21:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zillionx/9e15b1d23eb5e5110941 to your computer and use it in GitHub Desktop.
Save Zillionx/9e15b1d23eb5e5110941 to your computer and use it in GitHub Desktop.
How To Show And Hide Input Fields Based On Radio Button Selection
<html>
<!-- http://stackoverflow.com/questions/17621515/how-to-show-and-hide-input-fields-based-on-radio-button-selection -->
<head>
<script type="text/javascript">
function yesnoCheck() {
if (document.getElementById('yesCheck').checked) {
document.getElementById('ifYes').style.visibility = 'visible';
}
else document.getElementById('ifYes').style.visibility = 'hidden';
}
</script>
</head>
<body>
Yes <input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="yesCheck"> No <input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="noCheck"><br>
<div id="ifYes" style="visibility:hidden">
If yes, explain: <input type='text' id='yes' name='yes'><br>
What can we do to accommodate you? <input type='text' id='acc' name='acc'>
</div>
other 3<input type='text' id='other3' name='other3'><br>
other 4<input type='text' id='other4' name='other4'><br>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment