/ Published in: JavaScript
This simple script toggles element visiblity on a page based on a form field's current value.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript"> <!-- function showhide(what,obj) { // alert(what); if(what != "1") { obj1 = document.getElementById(obj); obj1.style.display = ''; } else { Â Â Â obj1 = document.getElementById(obj); Â Â obj1.style.display = 'none'; } } function hide(obj) { // alert(obj); obj1 = document.getElementById(obj); obj1.style.display = 'none'; } //--> </script> <!-- HTML form element that triggers toggle --> <input class="inputbox" type="radio" name="option" value="1" onchange="showhide(this.value,'toggle')" />Option 1<br/> <!-- HTML element that toggles --> <div id="toggle">This content will only be shown if option one is chosen</div>