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

Asked

Viewed 107 times

0

I wonder if someone could show me how I could open a modal to select a record in a table and return the code to a view text field so I can use when saving the form data, I am using the Framework with the adminLTE template.. I couldn’t implement...

follows example in phpMyAdmin:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

  • I managed to implement doing some research, I do not know if in the best way

1 answer

0

I was able to solve it, not in the best way, in case they want to position themselves 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>

Inputs for testing:

<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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.