Is there a way to link two HTML files containing jQuery within an HTML index file?

I'm currently working on creating an index page for a pair of HTML files that utilize jquery. Let's break down the structure of these files:

  • Emps1, Emps2: These are two HTML tables that start off empty.
  • TabA_stats, TabB_stats: Each HTML file has its own corresponding JS file to import data from .csv files and populate the tables.
  • Tab_A_4-1-2014, Tab_B_4-1-2014: These are two more HTML files that use the previously mentioned empty tables along with JavaScript to create filled out tables.
  • CSV_A_4-1-2014, CSV_B_4-1-2014: These are CSV files containing relevant data.
  • Index: This is where I want to link both Tab1 and Tab2.

My attempt is to reference both Tab_A_4-1-2014 and Tab_B_4-1-2014 within Index so that clicking on a link will execute either one of them on the same page.

The JavaScript logic involves matching the names of HTML tables (Tab_A_04-01-2014 and Tab_B_04-01-2014) with the dates in the CSV files (CSV_A_4-1-2014, CSV_B_4-1-2014) to display the corresponding data within the tables.

Despite my efforts, I am encountering an issue where the tables do not populate as intended. Upon debugging, I suspect that the problem arises when the JS attempts to retrieve the file name:

TabA_stats (problematic snippet):

var path_data = location.pathname.split("_");
var date_info = path_data[2].split(".");
var log_date = date_info[0];
$("#logdate").text(log_date);

It appears that the JS files only recognize the file as index.html and fail to locate the necessary CSV file for data population.

How can I troubleshoot this issue effectively? Your detailed explanation would greatly assist me, especially since I am relatively new to JS and JQuery, having only spent a week learning it.

EDIT:

Tab1_4-1-2014 (initial focus on the first table):

<html>
    <head>
     <script type="text/javascript" src="jquery-latest.js"></script>
     <link rel="stylesheet" type="text/css" href="tab1_style.css">
    </head>

    <body>

      <div id="tabA_stats_div">       
      </div>

      <script>    
       //load HTML layout, tables into div "ess_stats_div" 
       $('#tabA_stats_div').load("tabA_stats.html");

       //load js file "tabA_stats.js" and run
       $.getScript('tabA_stats.js');           
      </script>

    </body>

</html>

index (currently focusing on tab1):

    <head>
     <script type="text/javascript" src="jquery-latest.js"></script>
     <link rel="stylesheet" type="text/css" href="ess_style.css">
    </head>

    <body>

      <div id="topBar">
    <a href ="#" id="load_home"> Tab1 </a>
</div>
<div id ="content">        
</div>

<script>
    $(document).ready( function() {
    $("#load_home").on("click", function() {
        $("#content").load("Tab_A_04-01-2014.html");
    });
});
</script>

    </body>

</html>

Answer ā„–1

Zero-based indexing is a concept in Javascript that you should be aware of. When trying to extract information following the initial underscore, utilize the following code snippet:

var data_info = split_path[1].split(".");

as opposed to

var data_info = split_path[2].split(".");

Answer ā„–2

The issue you are encountering is completely normal; the JavaScript location object contains details regarding the current URL (click here). Therefore, if this script (referred to as part of TabA_stats) is executed on index.html in the root directory, then location.pathname will simply return that same file (index.html), assuming it's being run on a server and not locally viewed, where the full directory path would be included.

Now, let's delve into the inner workings of your browser. When you access your homepage (index.html), your browser sends a request to the server asking for the file index.html. Once the HTML file is received by your browser, it starts parsing through it, extracting any components it needs (such as JavaScript files, images, etc.) and generates requests for those elements, sending them back to the server. Your browser also starts rendering what it can process immediately while continuing to load other resources as they become available (although the exact process may vary slightly based on the browser, the concept remains consistent).

Let's pause there; where does this leave us? At this point, you have a fully loaded DOM, or Document Object Model. Essentially, this represents a tree structure of all HTML elements within the page. Has any JavaScript code been executed yet? Likely yes, but using something like $(document).ready(); allows us to defer our jQuery code (which typically interacts with/manipulates the DOM) until after the complete loading of the DOM. Remember, JavaScript serves as the language foundation, while jQuery functions as an extension or library built upon JS.

Beyond the initial concern highlighted earlier, the modifications made to your post suggest a complex layering system at play. It almost gives the impression of applying Object-Oriented principles to web development. Let's discard the notion that each table stands alone as a separate "object," necessitating its own HTML file. Instead, consolidate all components into minimal resources to enhance user loading speed.

Your setup could potentially streamline down to 1 HTML file and 1 JS file (assumed CSV files serve as external data sources subject to changes). Within your index.html file, include both tabs housing respective table requirements. Define everything as static HTML unless dynamic data must be fetched post-request (e.g., your CSV files). In such cases, leverage jQuery's AJAX functionality to fetch CSV data subsequent to DOM loading.

To summarize: Given the circumstances, research extensively PRIOR TO proceeding further. I advise reevaluating the current structural approach and project mindset. Begin with 1 HTML file and 1 JS file; strive to incorporate as much static HTML before resorting to JS for dynamic data handling. Once accustomed to these concepts, pose specific queries to move forward effectively!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Modifying multiple heading tags simultaneously with jQuery

Currently utilizing jQuery to append a string to all heading tags (h1, h2,..., h6) and display it on the screen. Seeking guidance specifically for the replacing aspect, and open to solutions using plain javascript as well. The code I have so far, which I ...

How can I ensure that the scripts returned in HTML via AJAX are executed when using $.load()?

I have been trying to make an AJAX call and receive a partialView which contains some script that needs to be executed. I did some research and learned about the "eval" method, but then discovered that the $.load() method should handle this for me. Howeve ...

Harmonizing various client viewpoints in a ThreeJS scene featuring a unified mesh structure

I am fairly new to ThreeJS and I am curious to know if it is possible to achieve the following, and if so, how can it be done: Two web browser clients on separate machines want to load the same html-based Scene code, but view it from different perspective ...

Focus on selecting the first child <li> element that contains an <a> tag within it

Struggling a bit with selecting only the first child within a li tag that contains a link. HTML: <ul class="dropdown-menu" role="menu" aria-expanded="true"> <li role="presentation" class="dropdown-header">Label</li> <li><a ...

How can we improve our handling of cyclic requires and EventEmitter in our code?

My user service code looks like this: 'use strict'; let events = require('services/events'); module.exports = { create: function (data) { doCreate(data).then(user => { events.emit('user.create'); ...

The Google Pie chart is displaying outside of the designated div area when placed inside a dropdown menu

Encountering an issue with my pie chart rendering outside of its parent div when placed within a dropdown menu. The chart successfully loads after the page is loaded, but only displays correctly if I hover over the dropdown and allow it to load. If I do ...

The Blueimp File Uploader seems to be sending numerous submissions at once

I've been tasked with fixing an issue on our site that I didn't originally build. The previous developer who worked on this project is now occupied with another task, leaving me to figure out what's going wrong. We are utilizing the basic bl ...

The e2e Protractor test is unable to identify the Angular component within a complex Angular router with multiple layers

I am currently working on an Angular application and I need to set up end-to-end testing for this project. Angular Package: 4.6.6 Protractor: 5.3.0 In addition, my project includes a multi-layer router that wraps the router-outlet into another component ...

Guide on using jQuery Ajax to send form data to another cs file in ASP.Net

How can I create a form to submit data to another CS file in order to update the database. Below is the form and corresponding code. <form id="form1" runat="server" action="./update.aspx" class="col-md-10"> <asp:Table ID="GridView1" class= ...

Unchecked checkbox displays as checked in UI

I am facing an issue with checking checkboxes using JavaScript. Even though the checkbox appears to be checked in the program, it does not reflect the updates on the user interface. If anyone has a solution for this, please share. <!DOCTYPE html> ...

Transferring data to a PHP script using the power of jQuery

Imagine a scenario where there are two links available. <li><a href="#" id="VALUE1" class="charName">Name 1</a></li> <li><a href="#" id="VALUE2" class="charName">Name 2</a></li> Now, when one of these link ...

Tips for organizing the router.js file in VueJs

With my router.js file currently reaching around 500 lines, Iā€™m looking for a better way to structure it. { path: "/", component: () => import("./../src/views/dashboard/Dashboard.vue"), meta: { auth ...

Numerous Radio Buttons

I am currently working on creating a quiz similar to those found on Buzzfeed and Zimbio. I apologize if this question has been asked before, but despite my efforts in searching, I have not been able to find the answer I am looking for. In this quiz, partic ...

An unforeseen issue arose while trying to update the data in a Chart.js chart within a Vue application

I am currently utilizing Chart.js version 3.5 along with Vue 3. After successfully creating a chart, I attempted to trigger a data change within a Vue method. However, I encountered an issue that displayed the following error message: "Uncaught TypeError: ...

Is it possible to utilize the same database connection for multiple routes in an

I have taken inspiration from Express's route-separation example and created a Node.js app. Now, I aim to enhance it by integrating the MongoDB driver Mongoose for listing Users and Kittens. var express = require('express'); var app = expre ...

What is Angular's approach to handling a dynamic and unprocessed JSON object?

When a JSON file is placed under assets, accessing it using something like http://localhost:4200/myapp.com/assets/hello.json will fetch the JSON file directly without any graphical user interface. This indicates that Angular must be able to return a raw JS ...

What is the best way to create documentation for node.js APIs that already exist

Just started learning Node, and feeling overwhelmed by all the different libraries available for the same purpose. It's frustrating to see so many options but not making any progress. I have an existing Node.js + Express application and I am trying t ...

What is the best way to read a local text file and store its contents in a string variable within a

Within my ReactNative project, I am seeking to retrieve the content of static text files and store it in a string variable. Here is an example of how I would like to achieve this: var content = loadPlainTextFile("resources/tags.txt"); var tags = content.s ...

Use PHP to highlight the row that has been selected in an HTML table

I am currently working on a project where I have styled multiple HTML tables on my website using alternating gray and white bands. Now, my goal is to highlight the selected row in a darker shade of gray. I have experimented with various solutions, and the ...

Express.js throwing an unexpected 404 error

I'm really struggling to understand why Node (express) only renders the index page and returns a 404 error for other pages, like "comproAffitto" in this example. In my app.js file: var index = require('./routes/index'); var comproAffitto= ...