Button value within table

0

I have a dynamically generated table, inside it I have a button to which I want to obtain its value

The button performs an action different to what is assigned its value, so I have assigned it a value there to use it in another action

I am trying to do it in the following way

var boton =document.getElementById("tabProd").rows[indice_fila_tabla].cells[6];
alert(boton.value);

However I can not get that value

    
asked by Leo T 26.01.2018 в 19:05
source

2 answers

0

If by value you mean the text of a DOM element, one option is to use textContent . Example:

A small table with two rows is included. The second row has two cells, the second cell has as text 5 . The text of the second cell of the second row is printed to the console log.

var celda = document.getElementById('miTabla').rows[1].cells[1];
console.log(celda.textContent)
<table id="miTabla">
  <tr></tr>
  <tr>
    <td></td>
    <td>5</td> 
  </tr>
</table>
    
answered by 27.01.2018 в 21:52
0

My JavaScript

<html>
        <button class="massshow-modal btn btn-info" 
        data-id="34"
        data-nombre="marcos"
        data-apellido="alberto"

        ><span class="glyphicon glyphicon-edit"></span> Editar</button>

        <button class="massshow-modal btn btn-info" 
        data-id="31"
        data-nombre="marcos_3"
        data-apellido="alberto_4"

        ><span class="glyphicon glyphicon-edit"></span> Editar</button>

</html>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>


<input type='text' class='form-control' id='id_mass' maxlength='45'   required='required' autofocus>
<input type='text' class='form-control' id='nombre_mass' maxlength='45'   required='required' autofocus>
<input type='text' class='form-control' id='apellido_mass' maxlength='45'   required='required' autofocus>

<script type='text/javascript'>

  // Show a post
        $(document).on('click', '.massshow-modal', function() {
            //$('.modal-descripcion').text('Vista de los Datos');
            //$('#msdelete').text(' ');
            $('#id_mass').val($(this).data('id'));
            $('#nombre_mass').val($(this).data('nombre'));
            $('#apellido_mass').val($(this).data('apellido'));

            //$('#massModal').modal('show');
            //$('#acciones').attr('class', 'btn btn-info hibe');
            //$('#acciones').text('Visible');
            //$('#acciones').attr('disabled');

        });
</script>


</body>
</html> 
    
answered by 07.04.2018 в 23:52