Table with Radio input how to pick the selected value

0

Hello, I have a table that has a line where you can select a radio button. When I select the save button I want to get the values that were selected. I can get the text from the radio button, however I can not get the selected value.

enter the code

    var table = document.getElementById("tbl");
        for (var i = 1,row; row = table.rows[i]; i++) {
            rows = table.getElementsByTagName('tr');
            var cells = rows[i].getElementsByTagName('td');

          
            alert(cells[2].innerText);
        }
         <tr>
             
                <td>
                  
                <label>
                    Presente
                    <input type="radio" name="@item.Id" value="1" checked>
                </label>

                <label>
                    Ausente
                    <input type="radio" name="@item.Id" value="0">
                </label>
                <td/>

            </tr>
    
asked by anonymous 02.03.2016 / 15:00

1 answer

0

Use the document.querySelectorAll method to search for the desired element. It will return an array, as it is an input of the radio type, you will only get the element [0].

input [type = radio] - search all input elements of the radio type

: checked - all radio-type input that is selected

document.querySelectorAll('input[type=radio]:checked')[0].value;
    
02.03.2016 / 15:29