-1

I am fetching data from firebase realtime database and displaying it in form of table.I want to make a row in a table as a link to another page but when i am adding tag inside script tag its not working and it is showing an error.

code JS

<script>
    var fbRef = firebase.database().ref().child("Sell_Products");
fbRef.on("child_added", snap => {
    var name = snap.child("name").val();
    var price = snap.child("price").val();
    var category = snap.child("category").val();
    var description = snap.child("description").val();
    var image = snap.child("image").val();
    $("#ex-table").append("<tr><td><a href="auction.html">/*here it is showing error "missing ) after argument list"*/<img src=" + image + "/img></a></td><td>" + name + "</td><td>" + price + "</td><td>" + category + "</td><td>" + description + "</td></tr>" );
});

How to solve this error and if this process is wrong then how can i make an image as link to another page. Thanks in advance

Abhishek Kumar
  • 57
  • 1
  • 2
  • 11

1 Answers1

0

In your href you used double quote ("). As your string start with double quote so whenever you use double quote it means end of the string. You have to concat it with + or use single quote.

$("#ex-table").append("<tr><td><a href='auction.html'><img src='" + image + "'/></a></td><td>" + name + "</td><td>" + price + "</td><td>" + category + "</td><td>" + description + "</td></tr>" );

atiq1589
  • 2,227
  • 1
  • 16
  • 24
  • Thanks for your answer. One more question if i want to make entire row as a link to another page what should i do? – Abhishek Kumar Apr 01 '18 at 11:12
  • What's wrong with: `$("#ex-table").append("" + name + "" + price + "" + category + "" + description + "" );` – Mamun Apr 01 '18 at 11:17
  • @Mamun you need to add href value as string. here auction.html isn't a valid string. – atiq1589 Apr 01 '18 at 11:28
  • @AbhishekKumar I think https://stackoverflow.com/questions/17147821/how-to-make-a-whole-row-in-a-table-clickable-as-a-link?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa will be helpful for you. – atiq1589 Apr 01 '18 at 11:30
  • Then `(" – Mamun Apr 01 '18 at 11:36