Deactivate Combo select

Asked

Viewed 170 times

0

Expensive;

I tried several ways to disable the Select combo (mespgto) when the checkbox (radio04) is set to "checked=true", but without success. Could you help me?

Obs: The way the function is (release), it comes only to lock the combo select, and is not the expected behavior.

Follows excerpt from the code:

     <script>

     function liberar() {

    if  (document.getElementById('radios03').checked==true)
    {
    document.getElementById('parcela').disabled=false
    }



    if  ( document.getElementById('radios04').checked==true)
    {
          document.getElementById('parcela').disabled=true

          document.getElementById('parcela').value=""

          document.getElementById('mespgto).disabled=true
    }

   }

    </script>



    <div class="form-group">
  <label class="col-md-4 control-label" for="textinput">Parcelado: </label>  

  <div class="col-md-4">
  <div class="radio" onchange="liberar();">
    <label for="radios-0">
      <input type="radio" name="radio" id="radios03" value="Sim" >
      Sim
    </label>
    </div>
  <div class="radio" onchange="liberar();">
    <label for="radios-1">
      <input type="radio" name="radio" id="radios04" value="Nao" checked="checked">
      Não

    </label>
    <p>
    </div>

 <label><input  type="text" disabled id="parcela" onkeyup="somenteNumeros(this);" name="parcela" maxlength="2"  style="width:50px;"  class="form-control input-md">
 Máximo 12 parcelas
  </label>
  <p id="saida"></p>
    </div>
</div>

<form name="mespgto" >
<div class="form-group">
  <label class="col-md-4 control-label" for="radios">Meio de Parcelamento:</label>

  <div class="col-md-4">
  <select class="mespgto" id="mespgto" name="financeiro" >
  <option  disabled selected>Selecione</option>
  <option value="xxx" id="xxx"   >xxx</option>
  <option value="yyy" id="yyy"  >yyy</option>
  <option value="www" id="www"  >Santander www</option>
  <option value="outros" id="outros"   >Outro</option>

  </select>
</div>
</div>
</form>`

2 answers

0


You’re one down ' on the line document.getElementById('mespgto).disabled=true example in fiddle

function liberar() {

  if (document.getElementById('radios03').checked == true) {
    document.getElementById('parcela').disabled = false
  }

  if (document.getElementById('radios04').checked == true) {
    document.getElementById('parcela').disabled = true
    document.getElementById('parcela').value = "";
    document.getElementById('mespgto').disabled=true
    }
  }
  • Good Moshmage, actually it was a copy error, but I was wrong in logic, in the release function, where I fixed now. You know that infallible method where you stop doing it when n can solve it and come back after a few hours and realize you were missing out on something simple? so it was.

0

    <div class="form-group">
      <label class="col-md-4 control-label" for="textinput">Parcelado: </label>  

      <div class="col-md-4">
      <div class="radio" onchange="liberar();">
        <label for="radios-0">
          <input type="radio" name="radio" id="radios03" value="Sim" >
          Sim
        </label>
        </div>
      <div class="radio" onchange="liberar();">
        <label for="radios-1">
          <input type="radio" name="radio" id="radios04" value="Nao" checked="checked">
          Não

        </label>
        <p>
        </div>

     <label><input  type="number" disabled id="parcela"  name="parcela" maxlength="2"  style="width:50px;"  class="form-control input-md">
     Máximo 12 parcelas
      </label>
      <p id="saida"></p>
        </div>
    </div>

    <form name="mespgto" >
    <div class="form-group">
      <label class="col-md-4 control-label" for="radios">Meio de Parcelamento:</label>

      <div class="col-md-4">
      <select class="mespgto" id="mespgto" name="financeiro" >
      <option  disabled selected>Selecione</option>
      <option value="xxx" id="xxx"   >xxx</option>
      <option value="yyy" id="yyy"  >yyy</option>
      <option value="www" id="www"  >Santander www</option>
      <option value="outros" id="outros"   >Outro</option>

      </select>
    </div>
    </div>
    </form>`


         <script>

         function liberar() {

            document.getElementById('parcela').disabled=true
            if  (document.getElementById('radios03').checked==true)
            {
                document.getElementById('parcela').disabled=false
            }


            document.getElementById('parcela').disabled=false

            document.getElementById('parcela').value=""

            document.getElementById('mespgto').disabled=false

            if  ( document.getElementById('radios04').checked==true)
            {
                  document.getElementById('parcela').disabled=true

                  document.getElementById('parcela').value=""

                  document.getElementById('mespgto').disabled=true
            }

           }

        </script>

Browser other questions tagged

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