I need to create a shopping cart. The first thing to do is to list the catalogue in a table using JavaScript. I am able to list it in one long list like table but I want the page to display 10 items at a time.
For example: Product ID, Product Name and Price are my three columns. I want these columns to repeat 4 times over. The code I have so fat is:
//Initialize Constants
TABLE_BEGIN = "<table border='1'>";
TABLE_END = "</table>";
TABLE_HEADING_BEGIN = "<th>";
TABLE_HEADING_END = "</th>";
TABLE_ROW_BEGIN = "<tr>";
TABLE_ROW_END = "</tr>";
TABLE_COLUMN_BEGIN = "<td>";
TABLE_COLUMN_END = "</td>";
UNDERLINE = "<hr>";
// Shopping cart based arrays
var orderedProductCodeArr = new Array()
var quantityArr = new Array()
// Creating the catalogue
document.writeln("<h1>HomewareCity Catalogue</h1>");
document.writeln(UNDERLINE);
// Create Table for catalogue
document.writeln(TABLE_BEGIN);
document.writeln(TABLE_HEADING_BEGIN + "Item ID" + TABLE_HEADING_END + TABLE_HEADING_BEGIN + "Product Name" + TABLE_HEADING_END + TABLE_HEADING_BEGIN + "Price" + TABLE_HEADING_END +
TABLE_HEADING_BEGIN + "Item ID" + TABLE_HEADING_END + TABLE_HEADING_BEGIN + "Product Name" + TABLE_HEADING_END + TABLE_HEADING_BEGIN + "Price" + TABLE_HEADING_END +
TABLE_HEADING_BEGIN + "Item ID" + TABLE_HEADING_END + TABLE_HEADING_BEGIN + "Product Name" + TABLE_HEADING_END + TABLE_HEADING_BEGIN + "Price" + TABLE_HEADING_END +
TABLE_HEADING_BEGIN + "Item ID" + TABLE_HEADING_END + TABLE_HEADING_BEGIN + "Product Name" + TABLE_HEADING_END + TABLE_HEADING_BEGIN + "Price" + TABLE_HEADING_END);
// List all the products
for(i = 0; i<=productListArr.length; i++){
document.writeln(TABLE_ROW_BEGIN);
document.writeln(TABLE_COLUMN_BEGIN + i + TABLE_COLUMN_END + TABLE_COLUMN_BEGIN + productListArr[i] + TABLE_COLUMN_END + TABLE_COLUMN_BEGIN + priceListArr[i] + TABLE_COLUMN_END);
document.writeln(TABLE_ROW_END);
}
document.writeln(TABLE_END);
This code does work for me. I have not included the declaration of i since there are a lot of other things that are not related to this question there.