Return code from a record to a code field in the view via a modal

0

I would like to know if someone could show me how I could do to open a modal select a record in a table and return the code to a text field of the view so I can use it when saving the form data, I am using the framework laravel with the adminLTE template .. I could not implement ...

Follow the example in phpMyAdmin:

    
asked by anonymous 31.08.2017 / 16:27

1 answer

0

I was able to solve it, it was not in the best shape, if you want to position yourself for improvement, thank you ...

JavaScript:

<script type="text/javascript">
  function devolveid(id, name) {
    document.getElementById('id_request').value = id;
    document.getElementById('name_request').value = name;
    $('#modalCidade').modal('hide');
  }
</script>

Test Inputs:

<input type="text" id="id_request" name="id_request" value="" />
                    <input type="text" id="name_request" name="name_request" value="" />
                    <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#modalCidade">Abrir Modal</button>

Modal:

                    <div id="modalCidade" class="modal fade" role="dialog" data-backdrop="static">
                        <div class="modal-dialog modal-lg">
                            <!-- Modal content-->
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                                    <h1>{{ trans('adminlte_lang::message.title') }} - Selecione uma cidade</h1>
                                </div>
                                <div class="modal-body">

                                    <div id="TableExt" style="box-shadow: 1px 1px 6px silver; padding: 20px; background-color: white;">

                                        <div class="row">

                                            <div class="col-xs-12">

                                    <table class="table table-bordered table-hover dt-responsive">
                                        <thead>
                                        <tr>
                                            <th>NOME</th>
                                            <th>AÇÃO</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        @foreach($empresas as $e)
                                            <tr>
                                                <td hidden>{{$e->name}}</td>
                                                <td>
                                                    <button type="button" class="btn-link" onclick="devolveid('{{$e->id}}', '{{$e->name}}')">{{$e->name}}</button>
                                                </td>
                                            </tr>
                                        @endforeach
                                        </tbody>
                                    </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="newDoc()">Fechar</button>
                                </div>
                            </div>
                        </div>
                    </div>
    
31.08.2017 / 20:06