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

227
Views
(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
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!