Enable field by selecting "Type"

Asked

Viewed 263 times

2

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 when selecting idTipo, and if it is idTipo = 60, then enable the time fields that we have below... How to do this in Jquery?

This jQuery does the search of the next field (which I did not put in the code ai), but we can integrate in this 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);
            }
        );
    }

1 answer

1


You can have an event receiver in jQuery that detects whether the select has changed and for the value 60. Place or remove the disabled.

It would be something like that:

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: http://jsfiddle.net/ctr0wj6r/

Browser other questions tagged

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