Doubt with Jquery and select

1

I'm maintaining a code from another programmer and I'm having difficulty with two select.

I need to get the time for each field and add up this interval, until then, okay, I've done some tests using the Moment.js lib and it caters me perfectly. What I'm having headache is in picking the values from the select.

In the code there is a mixture of pure HTML with a page rendering framework, TWIG. I've tried several ways to read the name, and it always returns me Undefined.

Follow the snippet of the code.

<fieldset class="datas">
            <legend class="text-center bg-default border-control">Datas</legend>
            <div id="container-data" class="col-xs-10 col-sm-10 col-xs-offset-1 col-sm-offset-1">

                <div class="form-group linha-data-template hidden">
                    <div class="col-sm-1">
                        <label class="control-label" for="inputDataTemplate">Data</label>
                    </div>
                    <div class="col-sm-3">
                        <div class="input-group">
                            <input name="inputDataTemplate" id="inputDataTemplate" type="text" class="inputDataTemplate form-control input-sm" placeholder="99/99/9999" maxlength="10" pattern="[0-3][0-9]/[0-1][0-9]/[2][0][1][1-9]" />
                            <span class="input-group-addon input-sm btn-calendar" style="cursor:pointer;">
                                <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                        </div>
                    </div>
                    <div class="col-sm-1 ">
                        <label class="control-label" for="cbHorarioIni">Horário</label>
                    </div>
                    <div class="col-sm-2">
                        {{ form_dropdown('cbHorarioIniTemplate', horarios, agendai.A106_Codigo, 'id="cbHorarioIniTemplate" class="input-sm form-control"') }}
                    </div>
                    <div class="col-sm-1 text-center">
                        <label class="control-label" for="cbHorarioFim">às</label>
                    </div>
                    <div class="col-sm-2">
                        {{ form_dropdown('cbHorarioFimTemplate', horarios, agendai.A106_Codigo, 'id="cbHorarioFimTemplate" class="input-sm form-control cbHorarioFimTemplate"') }}
                    </div>
                    <div class="col-sm-2">
                        <a id="removeData" style="cursor: pointer;"><h5><span class="glyphicon glyphicon-remove red"></span></h5></a>
                    </div>
                </div>
                {% for nro in 1..agendai.nro_datas %}
                <div class="form-group linha-data">
                    <div class="col-sm-1">
                        <label class="control-label" for="inputData">Data</label>
                    </div>
                    <div class="col-sm-3">
                        <div class="input-group">
                            <input name="inputData[]" type="text" class="form-control data input-sm data-esconder" placeholder="99/99/9999" required maxlength="10" pattern="[0-3][0-9]/[0-1][0-9]/[2][0][1][1-9]" value="{{set_value('inputData',agendai.datas[loop.index0].inputData)}}" />
                            <span class="input-group-addon input-sm btn-calendar" style="cursor:pointer;">
                                <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                        </div>
                    </div>
                    <div class="col-sm-1">
                        <label class="control-label" for="cbHorarioIni">Horário</label>
                    </div>
                    <div class="col-sm-2">
                        {{ form_dropdown('cbHorarioIni[]', horarios, set_value('cbHorarioIni', agendai.datas[loop.index0].cbHorarioIni), 'class="input-sm form-control selectpicker"') }}
                    </div>
                    <div class="col-sm-1 text-center">
                        <label class="control-label" for="cbHorarioFim">às</label>
                    </div>
                    <div class="col-sm-2">
                        {{ form_dropdown('cbHorarioFim[]', horarios, set_value('cbHorarioFim', agendai.datas[loop.index0].cbHorarioFim), 'class="input-sm form-control selectpicker"') }}
                    </div>
                    <div class="col-sm-2 green">
                        {% if loop.index == 1%}
                        <a id="addData" style="cursor: pointer;"><h5 class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-plus green "></span>&nbsp;&nbsp;Adicionar Data</h5></a>
                        {% else %}
                        <a id="removeData" style="cursor: pointer;"><h5 ><span class="glyphicon glyphicon-remove red "></span></h5></a>
                        {% endif %}
                    </div>
                </div>
                {% endfor %}
            </div>
</fieldset>

link

    
asked by anonymous 12.07.2017 / 20:11

1 answer

0
$(document).on('change', 'seletor do teu select' , function(e) {
        alert ( $(this).val() );
});

I did not understand why you used h1 as a parameter, but that should show what you want.

    
09.08.2017 / 14:24