I'm making a bookshop website (for a little college javascript project) So far all my book info is in arrays in a .js file which looks like this..
var headings = new Array(4);
headings [0] = "title"
headings [1] = "author"
headings [2] = "cat"
headings [3] = "bookid"
headings [4] = "cost"
var bookid = new Array(6);
var title = new Array(6);
var cat = new Array(6);
var author = new Array(6);
var cost = new Array(6);
var desc = new Array(6);
bookid [0] = "0001"
title [0] = "For whom the tell bowls";
cat[0] = "fiction";
author[0] = "John Doe";
cost[0] = "€12.99";
desc[0] = "This book is frickin' amazing blah blah blah"
and so on... there are 7 books...
Now I want to generate a table when I click on a thumbnail pic which has the author, title, cost etc. in one column and the actual corresponding details in the other column, Heres the code
for(var j = 0; j < 5; j++) {
row = document.createElement("tr");
// Each with 2 cells
for(var i = 0; i < 2; i++) {
var cell = document.createElement("td");
var temp = headings[j];
var temp2 = (temp + '[' + filename + ']');
if (i==1)
{var text = document.createTextNode(temp2);
}
else
{var text = document.createTextNode(temp);}
btw "filename" is passed to this function and it is the #of the book, eg, 0, 1, 2 and so on... Now, what displays on the page is sorta correct.. for book 0 I get..
title title[0]
author author[0]
cat cat[0]
bookid bookid[0]
cost cost[0]
and for book 1 I get
title title[1]
author author[1]
cat cat[1]
bookid bookid[1]
cost cost[1]
and so on, but details are not being interpreted as actual variables in an array. I'm guessing the solution has something to do with "innerHTML" or maybe casting my variables in some way..
If someone knows the solution to this it would be greatly appreciated!.. I'm planning to get this site finished today and move onto to something else more important (as this project is not worth many marks) But leaving this flaw in there would bug me!