Enable a text box with select

0

I'm trying to enable a text box with select with jquery

Here the code of js

<script>
  $('#RegistroInmueble5DeSeguro_id_moneda').on('change', function (e) {
    $(this).find('option').each(function () {
      $(this).removeAttr("disabled"); 
    });
    if (option.value === '4') {
      $('#RegistroInmueble5DeSeguro_otra_moneda')
        .attr('disabled', false);
    }
  });
</script>

the selector

El selector

</select>
<label 
  for="RegistroInmueble5DeSeguro_monto_asegurado"
  class="required">Monto asegurado <span class="required">*</span>
</label>
<input
  class="span5" name="RegistroInmueble5DeSeguro[monto_asegurado]"
  id="RegistroInmueble5DeSeguro_monto_asegurado" type="text" />
<label
  for="RegistroInmueble5DeSeguro_id_moneda"
  class="required">Moneda <span class="required">*</span>
</label>
<select
  name="RegistroInmueble5DeSeguro[id_moneda]"
  id="RegistroInmueble5DeSeguro_id_moneda">
  <option value="">Seleccione la moneda</option>
  <option value="1">Bolivar</option>
  <option value="2">Dolares</option>
  <option value="3">Euros</option>
  <option value="4">Otra Moneda</option>
</select>

and the form I want to enable with option 4 (another currency)

 <label
   for="RegistroInmueble5DeSeguro_otra_moneda"
   class="required">Otra Moneda <span class="required">*</span>
 </label>
 <input
   class="span5" maxlength="30" disabled="disabled"
   name="RegistroInmueble5DeSeguro[otra_moneda]"
   id="RegistroInmueble5DeSeguro_otra_moneda" type="text" />
    
asked by Carlos Alberto Bastidas Bustam 10.10.2018 в 02:24
source

1 answer

0

I recommend using .prop("disabled", false) or .prop("disabled", true) , instead of .attr() if you have Jquery > 1.6.

This detail is clarified in the Jquery documentation: link

    
answered by 10.10.2018 в 04:59