Enable field by selecting "Type"

1

I have the following field:

    <div class="line">
        <label class="control-label">Tipo</label>
        <select class="input-xxlarge idTipo" name="idTipo" id="idTipo" onChange="getParametro()" style="width: 715px !important;">
        <option value="">Selecione o Tipo</option>
        <option value="819">Faltas</option>
        <option value="60">Atrasos</option>
        <option value="69">Saída Antecipada</option>
        </select>
    </div>

<div class="line">
    <label class="control-label">Data Solicitado</label>
    <input id="dp1" class="input-small" style="width: 135px" name="data" type="date" required="required">

    <label class="control-label">Data Cadastro</label>
    <input id="dp1" class="input-small" style="width: 135px" name="data" type="date" required="required">

    <label class="control-label" style="width: 58px !important">Horários</label>
    <input id="dp1" class="input-small" name="hora_inicio" type="time" disabled>
    <input id="dp1" class="input-small" name="hora_final" type="time" disabled>
</div>

I would like that when I select the idType, and if it is idType = 60, then enable the time fields we have below ... How to do this in Jquery?

This jQuery does the search for the next field (which I did not put in the ai code), but we can integrate that jQuery to enable the time.

    function getParametro() {
        var id = $('#idTipo').val();
        $(".idParametro").append('<option value="0">Carregando...</option>');
        $.post("<? echo base_url(''); ?>faltas/ajax/parametro/" + id,
            {idParametro:jQuery(id).val()},
            function(valor){
                 $(".idParametro").html(valor);
            }
        );
    }
    
asked by anonymous 26.09.2015 / 18:25

1 answer

1

You can have an event drop-down in jQuery that detects whether the select has changed and the 60 value. There you enter or remove disabled .

It would look something like this:

var inputs = $('input[name="hora_inicio"], input[name="hora_final"]');
$('#idTipo').on('change', function(){
    if (this.value == '60') inputs.removeAttr('disabled');
    else inputs.attr('disabled', 'true');
});

jsFiddle: link

    
26.09.2015 / 19:13