capture data with a modal from a dynamic table

1

Good evening to those who read me, want to help me, I want to capture the values of a row of a table and display them in a modal

aui I have the table that comes from the database ...

<tbody id="myTable">

                @foreach($actividades as $actividad)
                <tr>
                    <td id="campId<?php echo $actividad->id; ?>">{{ $actividad->id }}</td>
                    <td id="campAct<?php echo $actividad->id; ?>">{{ $actividad->activiNomb }}</td>
                    <td id="campLog<?php echo $actividad->id; ?>">{{ $actividad->logNomb }}</td>
                    <td id="campCur<?php echo $actividad->id; ?>">{{ $actividad->curNomb }}</td>

                    <td align="right">
                        <?php echo $actividad->id ?>
                           <button id="{{ $actividad->id }}" type="button"  value"<?php echo $actividad->id; ?>" class="edit btn-floating btn-small waves-effect waves-light blue" style="margin-top:-0.8em; margin-bottom:-0.8em; float: left;">
                           <i class="fa fa-pencil" style="font-size:30px; color:#f9791e"></i> </bottom>

                    </td>
                    <td align="left">
                        <form action="{{ action('ActividadesController@destroy', $actividad->id) }}" method="post">
                            @csrf
                            <input type="hidden" name="_method" value="DELETE"/>
                            <button type="submit" class="btn btn-link" style="margin-top:-0.8em; margin-bottom:-0.8em;"><i class="fa fa-remove" style="font-size:30px; color:#f9791e"></i></button>
                        </form>
                    </td>
                </tr>

                @endforeach



            </tbody>

and here is the function that captures the data and puts them into the modal, which the problem is that I do not capture the id of the element and I put it empty

$(document).ready(function(){

    $(document).on('click', '.edit', function(){
        var pr= $('.edit').val();
        var id=$(this).val();
        console.log(pr);
        var ids=$('#campId'+id).text();
        var actividad=$('#campAct'+id).text();
//      console.log(actividad);
        var logro=$('#campLog'+id).text();
        var curso=$('#campCur'+id).text();

        $('#editModal').modal('show');
        $('#modId').val(ids);
        $('#modAct').val(actividad);
        $('#modLog').val(logro);
        $('#modCur').val(curso);
    });

});

    
asked by srJJ 24.06.2018 в 05:41
source

1 answer

1

If you want to get the id of the selected button, val() is not the appropriate method, you should use the method attr('nombreatributo') to get the value of the attribute id in this case.

$(document).on('click', '.edit', function(){
    var id=$(this).attr('id'); // this hace referencia al botón con la clase .edit
    console.log(id);
});

Keep in mind that id and value have the same value, it is more likely that it is better to keep one. If it is with value , the val() method would work.

    
answered by 24.06.2018 / 08:57
source