The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Creating Table in JavaScript Reply To: Creating Table in JavaScript


I just want to know how to add 2 tables where one will display on one page and the other on the next page within the same site. What am I misunderstanding here? I thought it is best to keep all scripts on one page for a small site.

Create a JavaScript file, and link it within each document. Store all the code in that one file. Each file that loads the script will have access to data, arrays, functions, etc that is defined in the JavaScript file.

Place the link right before the closing </body> tag. This way the Document Object Model (DOM) is loaded and ready for manipulation by JavaScript.

Then within your code, abstract each functionality of building a table by the way of function. Then you can do stuff like this:

var home = document.getElementById("ElementOnHomePage");
var buy = document.getElementById("ElementOnBuyPage");
// If we're on the home page print the home page table
if (home) {
  // call the function and pass pointer to the element we're manipulating
if (buy) {

Then later in your code you can define those two functions and have them build out each table.

Let me know if that makes sense.