Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

228
Vistas
(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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda