How to save value(task) in variable name ref in real time database?
P粉156532706
P粉156532706 2024-02-17 22:46:29
0
1
484

I'm trying to save a "task" in the live database and I want it to be saved in an account name reference. And it goes beyond the username.

Function to save tasks:

function savetask() {

  var task = input.value;
  //* ENVIA O VALOR DO INPUT (task)  ASSOCIADO AO NOME RECOLHIDO  A CIMA PARA A DATABASE DA FIREBASE
  firebase.database().ref('nomes').push(
    task
  );
  console.log('A seguinte tarefa foi enviada para a database:', task)

}
inputnota.addEventListener('submit', savetask)

Function to save name to database:

function savename(nome) {
    var nome = document.getElementById("nome").value;
    //* save in database
    firebase.database().ref('nomes').child(nome).push({
        'nome:':nome
    });
    console.log('teu nome:',nome)
    alert('Welcome:',nome)

    //* prevent form from submitting
    return false
}

P粉156532706
P粉156532706

reply all(1)
P粉021553460

You are missing nome in this snippet:

firebase.database().ref('nomes').push(
  task
);

So to make it write to the same path you need:

firebase.database().ref('nomes').child('salsa').push(
  task
);

Or read nome from HTML, just like you do in other code blocks:

var nome = document.getElementById("nome").value;
firebase.database().ref('nomes').child(nome).push(
  task
);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template