Disable a select with jquery when an input is not empty

0

Good morning.

I have tried it with a function but the detail is that the input is readonly , that is, the user can not write, the input is text type that feeds from a search engine, a code is brought and places it in that field, and tried placing onchange and nothing.

Could you tell me with an example? Thanks.

My code:

<input type="text" name="txtnumsoldes" id="txtnumsoldes" size="30" readonly="" />
<a href="javascript: ue_catalogo('solicitud.php?tipo=REPDES');" title="Catalogo"><img src="../shared/imagebank/tools15/buscar.gif" alt="Buscar" width="15" height="15" border="0" class="false" ></a>

<select name='cmb' id='cmb'  onclick='ue_div()' style=width:350px>;
<option value='-' >---seleccione--- </option>;

FUNCTION WHEN YOU GIVE A CLICK THE CODE PASSES IT TO MY FORM

function ue_aceptar_reportedesde(ls_numsol)
{
	opener.document.formulario.txtnumsoldes.value=ls_numsol;
	//opener.document.formulario.cmb.value="";
	//opener.document.formulario.cmb.disabled=true;
	}
	close();
}

What was commented was what I tried to do but in the search form I get an "indefinite" error because the cmb does not exist in that form, I do not know if you explain it well

    
asked by Rafael Aguilar 25.01.2018 в 18:48
source

2 answers

0

I think it would be something like this ...

 if ($('#txtnumsoldes').val()!='') {
            $('#cmb').attr('disabled',true)
        }
    
answered by 25.01.2018 в 19:45
0

In this case you will have to first check your search and then check the response of your input value.

I'm assuming queries by means of ajax, which will return the answer of your input, that same will be the one that will measure the length of the writing.

function busqueda(){
  $.ajax({
    datatype: "json",
    type: "POST",
    url: 'busqueda',
    data: { objBuqueda: objBuqueda},
    success: function (respuesta) {
      $("#txtnumsoldes").val(respuesta);
      var bandera = respuesta.length > 0;
      if(bandera){
        $("#cmb").prop({ readOnly: true });
       }
       else{
        $("#cmb").prop({ readOnly: false });
       },
    error: function () { }
    });  
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="txtnumsoldes" size="30" readonly/>

<select id='cmb'>
  <option value='-' >---seleccione--- </option>
  <option value='1' >Uno</option>
  <option value='2' >Dos</option>
  <option value='3' >Tres</option>
</select>
    
answered by 25.01.2018 в 19:53