ZK-2500z
ZK-2500z

Reputation: 63

Firebase pushes 1 input value and not Span?

I am attempting to push data into my firebase database. I managed to 1 user input field in. However now I am trying to have a span value in my database (which hanges its number based off a slider which controls it) This is the error which refers to my writeData function (down below)

Error: Reference.set failed: First argument contains undefined in property 'Exercise.setAm'

I have these two values which i get from the html:

const exerciseName = document.getElementById("exercise-search");
 const setAmount = document.getElementById("dynamicSet").innerHTML;

The exerciseName works fine and I see the result back in my DB:

DB

However my span doesnt seem to work here is my JS and the span field:

function writeData(){
    firebase.database().ref("Exercise").set({
        nameExercise: exerciseName.value,
        setAm: setAmount.value,
    })
}

<span id="dynamicSet"></span>

Do you see where I m going wrong? I also tried without innerHTML or without and value and without..

Upvotes: 0

Views: 78

Answers (1)

ultraGentle
ultraGentle

Reputation: 6349

Just do setAmount, not setAmount.value.

const exerciseName = document.getElementById("exercise-search");

Here you set exerciseName to an element

const setAmount = document.getElementById("dynamicSet").innerHTML;

But here you set setAmount to the innerHTML of an element.

So, apples and oranges:

Your first variable is set to the DOM representation an HTML element, so it will have various properties,

But your second variable is set to the string value of the innerHTML of a different element -- and as a string, it won't have those DOM properties.

Upvotes: 1

Related Questions