I am still finding my way around Javascript at the moment, so I apologize if I missed something really obvious with this (probably!).
I have a small form with several switches, for example:
<input type="radio" name="dtype" id="dtype" value="option1"> <input type="radio" name="dtype" id="dtype" value="option2"> <input type="radio" name="dtype" id="dtype" value="option3"> <input type="radio" name="dtype" id="dtype" value="option4">
Based on user selection, I need to immediately show the corresponding div. This works fine for me for the first radio, but not for subsequent ones (and there are no errors in Firebug). This is what I have right now;
<script type="text/javascript"> $(function() { $('#dtype').change(function() { if($(this).val() == 'option1') {$('#div1').slideToggle('500');} if($(this).val() == 'option2') {$('#div2').slideToggle('500');} if($(this).val() == 'option3') {$('#div3').slideToggle('500');} if($(this).val() == 'option4') {$('#div4').slideToggle('500');} }); }); </script>
I also tried "even if" at 3 after the first, without success. Pointers are welcome!
source share