Catch data from a select and declare variable

0

Alright? I am very new to programming and I have a simple question that I did not find here in the forum. I have this code below the view (made in codeigniter):

<div class="span6">
      <label for="formaPgto">Forma Pgto</label>

      <select name="formaPgto" id="formaPgto" class="span12">
        <option value="Dinheiro">Dinheiro</option>
        <option value="Cartão de Crédito">Cartão de Crédito</option>
        <option value="Cheque">Cheque</option>
        <option value="Boleto">Boleto</option>
        <option value="Depósito">Depósito</option>
        <option value="Débito">Débito</option>        
      </select> 

  </div>

I want that when the person chooses the Check option, open a field below, with an input type text, to enter the check number (OBS: I have already created the numCheque column and numCartao in the BD). And the same, when the user chooses Credit Card.

I could not figure it out. If anyone can help me, I'm so grateful.

    
asked by anonymous 31.08.2016 / 14:47

1 answer

1

I'll redo the answer with all the code for this case:

<div class="span6">
      <label for="formaPgto">Forma Pgto</label>

<select name="formaPgto" id="formaPgto" class="span12" onchange="yesnoCheck(this);">
        <option value="Dinheiro">Dinheiro</option>
        <option value="Cartão de Crédito">Cartão de Crédito</option>
        <option value="Cheque">Cheque</option>
        <option value="Boleto">Boleto</option>
        <option value="Depósito">Depósito</option>
        <option value="Débito">Débito</option> 
</select>
<input type="text" name="numCheque" id="numCheque" style="display: none">
  </div>

<script>
function yesnoCheck(that) {
    if (that.value == "Cheque") {
        document.getElementById("numCheque").style.display = "block";
    } else {
        document.getElementById("numCheque").style.display = "none";
    }
}
</script>

I apologize if any confusion, MDC.

PS: I tested the code and it works perfectly, you just have to pick it up and paste it into a file with .html extension.

Source: link

    
31.08.2016 / 16:47