Combo box with Maximo and Minimo

Asked

Viewed 17 times

-1

I need to create a combo box using a maximum and minimum amount for each row of my table based on a stock quantity record.

But I have no idea where to start.

Today my code is like this:

function _row(r) {
    var tr = document.createElement('tr')
    tr.innerHTML = '<td class="' + r.flag.toLowerCase() + '">' + r.flag + '</td>' +
        '<td>' + r.filialCode + '</td>' +
        '<td class="truncate">' + r.filialName + '</td>' +
        '<td>' + r.address + '</td>' +
        '<td>' + r.phoneNumber + '</td>' +
        '<td>' + r.distance + '</td>' +
        '<td>' + r.stock + '</td>' +            
    return tr
}

1 answer

0

function _row(r) {
    var td = document.createElement("td");
    var combobox = document.createElement("select");
    quantidade = r.Quantidade;
    for(x=0;x<=quantidade;x++){
      var option = document.createElement("option");
      option.value = x;
      option.innerHTML = x;
      combobox.appendChild(option);
    }
      combobox.appendChild(option);
    td.appendChild(combobox);
    
    var tr = document.createElement('tr');
    tr.innerHTML = '<td class="' + r.flag.toLowerCase() + '">' + r.flag + '</td>' +   
    '<td>' + r.filialCode + '</td>' + 
    '<td class="truncate">' + r.filialName + '</td>' + 
    '<td>' + r.address + '</td>' +   
    '<td>' + r.phoneNumber + '</td>' +        
    '<td>' + r.distance + '</td>' +
    '<td>' + r.stock + '</td>' ;
    
    tr.appendChild(td);
    return tr
}
objeto = {
flag:'empresa',filialCode:101010,filialName:'Facebook',address:'Rio das Ostras',phoneNumber:'22998',distance:1000,stock:'oi?',Quantidade:10}
linhas = _row(objeto);

$('#tabela').html(linhas);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id=tabela border=1px></table>

Browser other questions tagged

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