location.pathname is undefined
https://codepen.io/gsadopkgj/pen/oNJKxQR (i've put in the appropriate for the object property names - they now match the location.pathname)
20 Replies
but it says that this is the error in codepen tho (not on vscode): (this prevents the paragraph content from switching rn only the column headers are )
but when i define it with let's say: let path = location.pathname;
a new error occurs
it's not saying location.pathname is undefined, it's saying that the key of sections identified by the value of location.pathname is undefined
also
let path = location.pathname
doesn't do anything to location.pathname, it just stores the value (or lack thereof) in the path variable
when I add a console.log for location.pathname, it outputs this:
and that key just doesn't exist in your sections
arrayah
im confused
i try to call this singular javascript file
on multiple sub html pages
the index.html page is just one of them
but in the sections bit i never call the index.html?
i link all the other html subpages
I'm not sure what you mean by "call the index.html"
like here
the index.html page is irrelevant
for the sections code
i don't need the index.html page
okay, but location.pathname is set by the browser and contains "index.html"
i checked the location.pathname of only the specific subpages
and included those
is that wrong?
I really don't know what you mean by that. regardless though, you're trying to access sections[pathname], but the first key in the sections object is Descriptions, Justification, and so on
kk thanks
wait
so shld i take this out: " let path = location.pathname; "
then
cus it's unecessary
it's not really doing anything, if that's what you're asking
so how shld i go abt fixing that tho?
cus i sorta need it like that
do u understand what i'm trying to do?
im having it so that the text changes for each html subpage
but the text changing for each html subpage depends on the column headers
which are 'description 'justification' and so on
I think just switching from
sections[path][currentOption]
to sections[currentOption][path]
and the same for the default after ||
wait
i ahve it like this now
so that shld fix it?
hm it seems too one sec
i think i fixed it with just changing how i'm accessing sections but this is only trying it one one subpage so lemme try the others