Getting the sum of all radio button values to display in a table

后端 未结 3 2014
Happy的楠姐
Happy的楠姐 2021-01-29 13:14

I have some radio buttons in a table and I’ve set a value to them. When the user selects them and clicks the submit button, I want the sum of those values to show in another tab

相关标签:
3条回答
  • 2021-01-29 13:45

    You can create a function that you'll call on click in that you can use

    if (document.getElementById('a1_1_0').checked) { value = document.getElementById('a1_1_0').value; }

    And so on for all the Radiobuttons

    0 讨论(0)
  • 2021-01-29 13:49

    To get the value of an element, you can set an id to the element, then reference the element by id. ex.

    <script>
        function sumRadioInputs() {
            var valueOfInput = document.getElementById("someElementId").value;
        }
    </script>
    

    It is up to you to figure out how to chain all the inputs together

    0 讨论(0)
  • 2021-01-29 14:12

    First you need to get the value of the checked radio buttons

    The trick is to get it like this:

    $("input[name='a1_1']:checked").val();
    

    Code example

    Afterwards you can do whatever you want with the values.

    I hope this helps you.

    0 讨论(0)
提交回复
热议问题