Fill select text using a td of a table

0

I have the following code where I get the values of a table, and sent them to a form in modal . In a select I get the value but also that same value I want to leave it as the text of the select.

Function to obtain the data from the table.

var update_data = function(tbody, table) {

    $(tbody).on("click", "button.change", function() {
        var data = table.row($(this).parents("tr")).data();
        var folio = $("#id_folio").val(data.Folio),
            nombre = $("#nombre").html(data.NomOper),
            desde = $("#desde").val(data.FechaDesde),
            hasta = $("#hasta").val(data.FechaHasta),
            dias = $("#dias").val(data.TotalDias),
            tipo = $("#tipo").val(data.TipoAusencia);

             });
     }

My modal where I recover the data.

<div class="modal fade bd-example-modal-lg" id="myModalthree" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalCenterTitle">Modificar Ausencia</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form action="include/cambiarPassword.php" method="post">
                <div class="modal-body">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-8">
                                <h5>Se modificara ausencia de </h5>
                                <code id="nombre"></code>
                            </div>
                        </div>
                        <br>
                        <div class="row">
                            <div class="col-md-8">
                                <h5>Tipo Ausencia </h5>
                                <select class="form-control" value="" name="tipo">
                                    <option value="" id="tipo" selected></option>
                                    <option value="AUSENCIA S/JUSTIFICAR">AUSENCIA S/JUSTIFICAR</option>
                                    <option value="AUSENCIA JUSTIFICADA">AUSENCIA JUSTIFICADA</option>
                                </select>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-5">
                                <label class="col-form-label">Fecha desde</label>
                                <!-- <input type="date" name="desde" id="desde" value="" class="form-control"> -->
                                <input type="text" name="hasta" id="desde" value="" class="form-control">
                            </div>
                            <div class="col-md-5">
                                <label class="col-form-label">Fecha hasta</label>
                                <!-- <input type="date" name="hasta" id="hasta" value="" class="form-control"> -->
                                <input type="text" name="hasta" id="hasta" value="" class="form-control">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-2">
                                <label class="col-form-label">Dias</label>
                                <input type="text" name="dias" id="dias" value="" readonly class="form-control">
                            </div>
                        </div>
                    </div>
                    <input type="hidden" id="id_folio" name="folio" value="">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <input type="submit" name="submit" class="btn btn-primary" value="Modificar Ausencia" />
            </form>
        </div>
    </div>
</div>

In the option of the select I want to add the text of the attribute data.TipoAusencia

    
asked by MoteCL 14.08.2018 в 18:47
source

0 answers