Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
(JQuery) Output is undefined when getting a value from a dynamically created input

I am making an inventory database using JS and JQuery to firebase realtime database. The only problem I have now is when I input my values and run the function, it reads as undefined in the console log so it doesn't add data to the database and runs an error because it's undefined.

Uncaught Error: set failed: value argument contains undefined in property 'Inventory.undefined.Quantity'

This is the code to add inputs to the table:

$(".add-new").click(function(){
  $(this).attr("disabled", "disabled");
  var index = $("table tbody tr:last-child").index();
  var row = '<tr>' +
      '<td><input type="text" class="form-control" name="name" id="name"></td>' +
      '<td><input type="text" class="form-control" name="unit" id="unit"></td>' +
      '<td>' + actions + '</td>' +
  '</tr>';
  $("table").append(row);       
  $("table tbody tr").eq(index + 1).find(".add, .edit").toggle();
});

This is the code making the input into a variable:

$(document).on("click", ".add", function(){
            var empty = false;
            var input = $(this).parents("tr").find('input[type="text"]');
            input.each(function(){
                if(!$(this).val()){
                    $(this).addClass("error");
                    empty = true;
                } else{
                    $(this).removeClass("error");
                }
            });
            $(this).parents("tr").find(".error").first().focus();
            if(!empty){
                input.each(function(){
                    $(this).parent("td").html($(this).val());
                });         
                $(this).parents("tr").find(".add, .edit").toggle();
                $(".add-new").removeAttr("disabled");
                let name = $(this).parents("tr").find("input[name=name]").val();
                let unit = $(this).parents("tr").find("input[name=unit]").val();
                console.log(name,unit);
                set(ref(db, 'Inventory/' + name), {
                    Quantity: unit
                });
            }   
                
        });

This is the output for the console log:

undefined undefined

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda