Onselect / Javascript Event

0

I am trying to do that when the user selects the% s of% id from source, and the selection is "Client" the select id "cli" receive div .

For this I did a test, when to trigger the event display:block of the source id, give a onchange in the toogle of id cli, showing or hiding.

How do I do when the% selected% with value "Client" causes it to appear, and if not, to hide.

Code:

<div class="col-md-4" >
    <div class="form-group">
        <label class="formLabel" for="origem">Origem</label>
        <select name="origem" id="origem" class="form-control formSelect" onchange="origem()" required>
            <option value=""></option>
            <option value="Cellsystem">Cellsystem</option>
            <option value="Santosfilho">Santosfilho</option>
            <option value="Cliente">Cliente</option>
            <option value="Licitacao">Licitação</option>
            <option value="Leilao">Leilão</option>
            <option value="Mercado Livre">Mercado Livre</option>
        </select>
    </div>
    <div class="form-group">
        <label class="formLabel" for="prioridade">Prioridade</label>
        <select name="prioridade" id="prioridade" class="form-control formSelect" required>
            <option value="baixa">Baixa</option>
            <option value="media" selected>Normal</option>
            <option value="alta">Alta</option>
        </select>
    </div>
</div>
<div class="col-md-4">
    <div class="col-md-12 cli" id="cli">
        <div class="form-group">
            <label style="width:50%;text-align:left;font-weight:normal;color:#FF5C5C;" class="formLabel" for="nfvenda">NF</label>
            <label style="width:50%;text-align:center;font-weight:normal;color:#FF5C5C;" class="formLabel" for="datanfvenda">Data de emissão</label>
            <input style="width:49%;" type="text" class="form-control formInputFL" name="nfvenda" id="nfvenda" >
            <input style="width:49%;" type="text" class="form-control formInputFR" name="datanfvenda" id="datanfvenda" >
        </div>
        <div style="clear:both;height:10px;"></div>
        <div class="form-group">
            <label style="font-weight:normal;color:#FF5C5C;" class="formLabel" for="danfe">DANFE</label>
            <input type="text" class="form-control formInput" name="danfe" id="danfe" >
        </div>
        <div class="form-group">
            <label style="color:#FF5C5C;" class="formLabel" for="cliente">Quem é o Cliente ? </label>
            <input type="text" class="form-control formInput" name="cliente" id="cliente" >
        </div>
    </div>
</div>

Follow the Javascript:

function origem() {
    $( "#cli" ).slideToggle("fast", function() {});
}
    
asked by anonymous 03.08.2015 / 14:17

1 answer

1

Well, I would not use JQuery to do this check, to do what you want to use the onchange event and work as follows:

function origem(valor){
  if(valor == "Cliente"){
    document.getElementById("cli").style.display = "";
  }else{
    document.getElementById("cli").style.display = "none";
    
  }
  
}
<div class="col-md-4" >
  <div class="form-group">
    <label class="formLabel" for="origem">Origem</label>
    <select name="origem" id="origem" class="form-control formSelect" onchange="origem(this.value)" required>
      <option value=""></option>
      <option value="Cellsystem">Cellsystem</option>
      <option value="Santosfilho">Santosfilho</option>
      <option value="Cliente">Cliente</option>
      <option value="Licitacao">Licitação</option>
      <option value="Leilao">Leilão</option>
      <option value="Mercado_Livre">Mercado Livre</option>
    </select>
  </div>
  <div class="form-group">
    <label class="formLabel" for="prioridade">Prioridade</label>
    <select name="prioridade" id="prioridade" class="form-control formSelect" required>
      <option value="baixa">Baixa</option>
      <option value="media" selected>Normal</option>
      <option value="alta">Alta</option>
    </select>
  </div>
</div>
<div class="col-md-4">
  <div class="col-md-12 cli" id="cli">
    <div class="form-group">
      <label style="width:50%;text-align:left;font-weight:normal;color:#FF5C5C;" class="formLabel" for="nfvenda">NF</label>
      <label style="width:50%;text-align:center;font-weight:normal;color:#FF5C5C;" class="formLabel" for="datanfvenda">Data de emissão</label>
      <input style="width:49%;" type="text" class="form-control formInputFL" name="nfvenda" id="nfvenda" >
      <input style="width:49%;" type="text" class="form-control formInputFR" name="datanfvenda" id="datanfvenda" >
    </div>
    <div style="clear:both;height:10px;"></div>
    <div class="form-group">
      <label style="font-weight:normal;color:#FF5C5C;" class="formLabel" for="danfe">DANFE</label>
      <input type="text" class="form-control formInput" name="danfe" id="danfe" >
    </div>
    <div class="form-group">
      <label style="color:#FF5C5C;" class="formLabel" for="cliente">Quem é o Cliente ? </label>
      <input type="text" class="form-control formInput" name="cliente" id="cliente" >
    </div>
  </div>
</div>
    
03.08.2015 / 14:31