Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
(JQuery) La salida no está definida cuando se obtiene un valor de una entrada creada dinámicamente

Estoy creando una base de datos de inventario usando JS y JQuery para la base de datos en tiempo real de firebase. El único problema que tengo ahora es cuando ingreso mis valores y ejecuto la función, se lee como indefinido en el registro de la consola, por lo que no agrega datos a la base de datos y ejecuta un error porque no está definido.

Error no detectado: el conjunto falló: el argumento de valor contiene undefined en la propiedad 'Inventario.undefined.Quantity'

Este es el código para agregar entradas a la tabla:

 $(".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(); });

Este es el código que convierte la entrada en una 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 }); } });

Esta es la salida para el registro de la consola:

indefinido indefinido

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!