Here is the code to show input fields depending on radio selection like:
<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>
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>
However I would like input fields to be hidden (like on the image), and make they do not use any space until radio button is selected, when radio is selected show them with fade effect...
Here is the fiddle:
Answer: Use the jQuery show() and hide() methods You can simply use the jQuery show() and hide() methods to show and hide the div elements based on the selection of radio buttons. The div boxes in the following example are hidden by default using the CSS display property which value is set to none .
Replace all instances of visibility
style to display
display:none //to hide display:block //to show
Here's updated jsfiddle: http://jsfiddle.net/QAaHP/16/
You can do it using Mootools or jQuery functions to slide up/down but if you don't need animation effect it's probably too much for what you need.
CSS display is a faster and simpler approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With