-1

I am retrieving firebase database and want to display data on web page like category , description etc.How can i get that thing work?I want to display value next to text like category , description .

JS

var myParam = location.search.split('itemKey=')[1];
firebase.database().ref('/Sell_Products/' + myParam).once('value').then(function (snapshot) {
    var name = snapshot.child('name').val();
    alert(name);
    var image = snapshot.child('image').val();
    var category = snapshot.child('category').val();
    var description = snapshot.child('description').val();
    var price = snapshot.child('price').val();
    var user = firebase.auth().currentUser.uid;
    var databaseRef = firebase.database().ref("auction/");
    databaseRef.set({
        Image: image,
        category: category,
        description: description,
        price: price,
        uid: user
    });
    document.querySelector('#image').src = image;
});

HTML

<div id="image1">
    <div id="box">
        <img id="image" />
    </div>
</div>
<div>
    <div id="content">
        <p id="category">Category: </p>
        </br>
        <p id="name">Name:</p>
        </br>
        <p id="price">Price:</p>
        </br>
        <p id="decription">Description:</p>
        </br>
    </div>
</div>
<div id="btn">
    <button class="button">BID</button>
</div>

My web page

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Abhishek Kumar
  • 57
  • 1
  • 2
  • 11
  • Possible duplicate of [How to retrieve data from Firebase realtime database in Android?](https://stackoverflow.com/questions/42487574/how-to-retrieve-data-from-firebase-realtime-database-in-android) – mooga Apr 02 '18 at 10:52

1 Answers1

1

In your html add:

<p id="category">Category: <span id="categorytext">sample text</span> </p>

Then in the js file:

 firebase.database().ref('/Sell_Products/'+myParam).once('value').then(function(snapshot)
{var name=snapshot.child('name').val();
 alert(name);
 var image=snapshot.child('image').val();
 var category=snapshot.child('category').val();
 var description=snapshot.child('description').val();
 var price=snapshot.child('price').val();
 document.getElementById("categorytext").innerHTML = category;

});
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
  • I worked on your suggestion but unfortunately it didn't worked out.Any other way of doing it? – Abhishek Kumar Apr 02 '18 at 10:35
  • I have made use of where i want to show value which i am retrieving but nothing is getting showed up there.I have given id for each text area and in script tag i am writing document.getElementById("categorytext").innerHTML = category; categorytext is the id of the text area – Abhishek Kumar Apr 02 '18 at 10:40
  • check this: https://stackoverflow.com/a/21711717/7015400 @AbhishekKumar – Peter Haddad Apr 02 '18 at 10:45
  • Yes i have recorded my upvotes. @Peter Haddad can you please see this question https://stackoverflow.com/q/49638806/7633292 please.Thanks – Abhishek Kumar Apr 04 '18 at 05:50
  • regarding the link, the answer there is correct, it checks if the user is logged in or not – Peter Haddad Apr 04 '18 at 05:53