Hello I would like to ask if how to put data from firebase database into input text field? I tried it in any text label like, Label, h1, strong or anything and they getting it but when I put it in input text field its not changing or detecting.
This is the code my input text field.
<div class="md-input">
<label>First Name<span class="text-danger">*</span></label><br>
<div class="md-input">
<input class="md-form-control" type="text" id="firstname" name="firstname" placeholder=" " required>
</div>
and this is the javascript or my firebase code to move it in the input field but nothings happening.
firebase.auth().onAuthStateChanged(function(user)
{
if(!user)
{
window.location.href = "../signin.html";
}
else
{
var dbUser = firebase.auth().currentUser.uid;
firebase.database().ref('Freelancer/' dbUser).once('value').then(function (snapshot){
var okay = snapshot.val().name;
var okay1 = snapshot.val().email;
var okay2 = snapshot.val().pass;
var okay3 = snapshot.val().roles;
var okay4 = snapshot.val().userID;
console.log(okay);
console.log(okay1);
console.log(okay2);
console.log(okay3);
console.log(okay4);
document.getElementById("firstname").innerHTML=okay;
document.getElementById("lastname").innerHTML=okay1;
document.getElementById("phone").innerHTML=okay2;
document.getElementById("roles").innerHTML=okay3;
});
Hope someone can assist me or help me thank you!
CodePudding user response:
For <input>
elements, you need to use the value
property when setting (or getting) the text in the field.
document.getElementById("firstname").value = okay;