jquery - Javascript amelioration for option changer -
i guys, made script shows different div box each different radio button option check, starting 1 default option selected + right div shown in beginning.
heres jsfiddle it: demo
i use jquery on website. idea on how make js code cleaner, easier , simpler, in case have more possible options (up 10) ?
$("input[name='radio-269']").change(function() { if ($(this).val() == "1") { $('#1').removeclass("hidden"); $('#2').addclass("hidden"); $('#3').addclass("hidden"); } if ($(this).val() == "2") { $('#1').addclass("hidden"); $('#2').removeclass("hidden"); $('#3').addclass("hidden"); } if ($(this).val() == "3") { $('#1').addclass("hidden"); $('#2').addclass("hidden"); $('#3').removeclass("hidden"); } });
please remember numbers use value="" random number between 1 , 1000 (depending on mysql database entry).
thanks!
hi can this
$("input[name='radio-269']").change(function() { var val = $(this).val(); $("div.euro").hide(); $("#"+val).show(); });
on every div should add class 'euro' here example: http://jsfiddle.net/e9muf/1/
Comments
Post a Comment