Set firebase child name from text input

Viewed 25

This is input:

<input type="text" class="form-control" id="name" maxlength="10" required placeholder="Enter Username">

And this is Javascript:

contactsRef.child("users/" + auth.uid + "/moath")
.set({ a1: $('#name').val(),})

This is what I get hello

In JavaScript i have /moath I don't want it.

But I want to set child name from input

I have tried this:

contactsRef.child("users/" + auth.uid + "/('#name')")
.set({ a1: $('#name').val(), })

I've looked at this too but it wasn't helpful How do I set the name a child in Firebase to user input from a text field?

Finally this is I want

enter image description here

1 Answers

If I correctly understand your question, you need to do:

contactsRef.child("users/" + auth.uid + "/" + $('#name').val())
.set({ a1: $('#name').val()});
Related