function show radio selection value, conflict between several radio groups

0

I have three radio groups. and a function to show the value of the selected one, the same function for each one associated with the id of the radio group. To be clear create a file jsfiddle link

By showing the value of the selected input of a certain group, the one that has been selected from the first upper group, which already has some selection, is shown in three rows. If you start from the bottom row, it goes well, but once you have selected a higher one, when you change the selection of the lower group, the value of the first group that has a selection is displayed.

can be tested in the file with the link. I appreciate your interest. Greetings

    
asked by Hernan527 10.08.2018 в 06:21
source

1 answer

0

In princio you have a part well, but what you did when declaring the var $radChecked was this $(':radio:checked'); , with that you are calling all the radios of the body, and not the div where they are located, I have corrected the error , in if it is the line where you declare var $radChecked

<script type="text/javascript">
        $(function() {
            var $radBtn = $("#odontologia");
            $radBtn.click(function() {
                var $radChecked = $radBtn.find(':radio:checked');
                $("#forro").text('')
                    .append($radChecked.val());
            });
        });
        $(function() {
            var $radBtn = $("#optica");
            $radBtn.click(function() {
                var $radChecked = $radBtn.find(':radio:checked');
                $("#grito").text('')
                    .append($radChecked.val());
            });
        });
        $(function() {
            var $radBtn = $("#reintegros");
            $radBtn.click(function() {
                var $radChecked = $radBtn.find(':radio:checked');
                $("#para").text('')
                    .append($radChecked.val());
            });
        });
    </script>
    
answered by 10.08.2018 в 14:00