#How to display HTML Table that is inside a txt file in another HTML file
66 messages · Page 1 of 1 (latest)
yes you can but what kind of table? that's just like over complicating the process
you can use vanilla js using fetch function and then parse it to a div, or use jquery
lemme know which way to go, i'll help out
I would like to use a pure js process since I can’t use any type of library or databases backend in the office, So it would be helpful to have a table either as table.html or txt it doesnt matter for me and display that table in the main html and also the whole css and styling of the table is in the main html
but you said you have a table in a txt file, right?
yes its okay txt file, i can also generate that table to be exported as .html file
so either txt or .html its fine with me
okay, here goes, i'll assume you're using Output.txt
fetch('Output.txt')
.then(response => response.text())
.then(data => {
const parser = new DOMParser();
const htmlTable = parser.parseFromString(data, 'text/html').querySelector('table');
const container = document.querySelector('#table-container');
container.appendChild(htmlTable);
});
<div id="table-container"></div>
i think this shold work, basic domparser
okay ill test the code and see how it goes, Ill also send the full html file here for you to check it out
alright
Okay i found the biggest issue, the code worked as expected btw
why dont you just use react that'll make things easy for u
It only displays the table when im using a live server
"127.0.0.1:5500/index.html"
if i open the html without a live server it will not display the table
that's because you're using fetch() and depends browser to browser how that function is handled
to fix it you'll need ajax or jquery but you said, you can't use that
is there another way? because the employees will not have a live server just click on the html to fetch it?
can i write ajax without internet connection?
nope
what office doesnt have internet? but ig u can give xml a try
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
const parser = new DOMParser();
const htmlTable = parser.parseFromString(this.responseText, 'text/html').querySelector('table');
const container = document.querySelector('#table-container');
container.appendChild(htmlTable);
}
};
xhr.open('GET', 'Output.txt');
xhr.send();
The company i work out will not allow me to develop web systems or applications, lol im using notepad btw to write the html and scripts lol
whats this 🧐 ?
damn bro why're you even working there, i wouldnt stay a day at such a place
its an http request an alternative to fetch, if this doesnt work, it wont work that way
ill try it one moment
darn, it didnt work
Is it possible to do it with xml?, but how would i structure the html table inside xml format?
leave xml, its of no use
idk man that's such a weird question to me
i work with mern stack, without internet i dont exist, so umm yeah fool your boss and use ajax
or ig you can download the jquery script, and import it locally
That's the issue, i cant download it or insert a usb to computer, I was hoping to type the whole code if it was possible
how does that work in a company, you've given me something weird to think abt
So im not in the IT department, I work at a marketing department so obviously they don't use a "programming" language or tool and the IT won't provide one for me, So the team asked if i can do it using a notepad to write the whole thing, It works with static html pages but i want to extend it and make it automated for them because i have a made a VBA code in excel to export excel table as an HTML table and then "hopefully" display it and automate without the need for me to copy the table and pasted inside the .html file each time their is an update
wait a minute !!!!! If i paste this code inside HTML file and put it inside a comment "/", will the IT antivirus be able to detect it?
at the time of injecting it inside the share point
why would you put a comment?
and an i.t. antivirus that's the first time i ever heard of it, we either bring our own macbooks or mac minis just connect em up to display and start working and chill, yours sounds like a strict company nvm
but then even the while wont read it
ask em to allow jquery it'll make the whole thing just a 1 line function
Thanks for the tip brother, Ill try for that 👍
I downloaded the Jquery file, I wanna just test the process if you can continue helping
$(function() {
$('#table-container').load('Output.txt');
});
after importing the file
is this the correct way?
yeah
it doesnt work without a live server
then my frnd there's no way
because all webpages are meant to be deployed to internet not a local machine without a server
We have a sharepoint
however if you're all on same network you can use node
that works deploy the file to your network then
yes we are, how???
so if i add the file in the sharepoint folder it will automatically act as a live server?
i'll ask chatgpt to write the instructions, but basically yes