How do I find the table field name instead of the ID when I write the data to my table?

Asked

Viewed 30 times

-1

function cadLancamentos(adquirente, formadepagamento, valorformadepagamento, cupomformasdepagamento) {

  var tb = document.getElementById("dtAdquirente");
  var qtdLinhas = tb.rows.length;
  var linha = tb.insertRow(qtdLinhas);

  var cellCodigo = linha.insertCell(0);
  var cellAdquirente = linha.insertCell(1);
  var cellFormadepagamento = linha.insertCell(2);
  var cellValorformadepagamento = linha.insertCell(3);
  var cellCupomformasdepagamento = linha.insertCell(4);

  cellCodigo.innerHTML = qtdLinhas;
  cellAdquirente.innerHTML = adquirente;
  cellFormadepagamento.innerHTML = formadepagamento;
  cellValorformadepagamento.innerHTML = valorformadepagamento;
  cellCupomformasdepagamento.innerHTML = cupomformasdepagamento;
}
<div id="dfPessoas">
  <form name="fPessoas">
    <select class="custom-select my-1 mr-sm-2" id="formadepagamento">
      <option selected>Formas de Pagamento</option>
      <option>Elo Crédito</option>
      <!-- com o value informado, ele pega o valor que esta obtido no value -->
      <option>Elo Débito</option>
      <option>Alelo</option>
      <option>Visa</option>
      <option>Visa Electron</option>
      <option>Sodexo</option>
      <option>Mastercard</option>
      <option>Maestro</option>
      <!-- <option value="8">Maestro</option> // Quando remove o "value" ele pega o nome do campo -->
    </select>
    <label for="adquirente">*Adquirente</label>
    <select class='form-control form-control-sm' data-placeholder="Digite um nome p/ procurar o adquirente" name="txtAdquirentes" id="adquirentes"></select>
    <label for="inputAddress">Valor R$</label>
    <input type="text" name="txtValorformadepagamento" class="form-control" id="valorformadepagamento" placeholder="Valor">
    <label for="inputAddress">Cupom</label>
    <input type="text" name="txtCupomformasdepagamento" class="form-control" id="cupomformasdepagamento" placeholder="Cupom">
  </form>
</div><br>

<div class="container">
  <div class="row">
    <div class="col-md-3 text-center">
      <input type="button" value="Adicionar" onclick="cadLancamentos(adquirentes.value, formadepagamento.value, valorformadepagamento.value, cupomformasdepagamento.value)" />
      <div class="col-md-3 text-center">
        <button type="button" class="btn btn-warning">Limpar</button>
      </div>
    </div>
  </div>
  <hr>

  <div>
    <table class="table table-dark" id="dtAdquirente">
      <thead>
        <tr>
          <th scope="col">Codigo:</th>
          <th scope="col">Adquirente:</th>
          <th scope="col">Forma de Pagamento:</th>
          <th scope="col">Valor</th>
          <th scope="col">Cupom</th>
        </tr>
      </thead>
    </table>
  </div>

1 answer

1

It would be good to detail more your doubt.

But let’s try, when you’re saving, you can do a search and bring in an object the data you need.

if using sequelize you can do so:

const xpto = XPTO.findOne({where:{ id }});

foo will have the data you need, in Where you can search for any attribute you need.

  • cellAdquirente.innerHTML = ($(acquirer).find('option:Selected').text(); and the button field I just removed the value and it worked, vlw friend..

  • Good @Rafaelguilherme, congratulations, I had understood something beyond, but you wanted to get the name that was in the html table... but good that I right.

  • This is what I miss more clarification, as this was my 1 question, I thought I had a character limit to put...

  • Cool, the important thing is to start asking questions...that in the case has no limits, try to inform as much information, code snippets, flow of what you need, to facilitate understanding and help in the solution. congratulations... I’m new to stackoverflow tbem

Browser other questions tagged

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