Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How do I select elements from different HTML files with JavaScript?

Here are the files you'll need: https://github.com/sid-FBLA/FBLA, https://sid-fbla.github.io/FBLA/

The files you will need to open up from the repository are: index.html, HTML/bookings.html, and JS/selection.js

What on the website on the homepage if you scroll down a little you will notice names of different states and cities if you press the 'BOOK' button it will redirect you to the bookings page. I am trying to make it so that if the user presses the 'BOOK' button on a particular state, the corresponding arrival option will be selected. However, this is an issue, as the elements I am manipulating are on different pages, how do I go about this, at the moment I am getting the error null for Baltimore and all subsequent queries(it "works" for Boston and Cleveland because there are elements on the bookings page, that match the selection criteria).

1 Answer

Steven Parker
Steven Parker
229,744 Points

Only the resources on the current page are available to the program. You can use an advanced browser feature called local storage to pass some information on to the program loaded by the next page.

There's a workshop here called Using Local Storage with JavaScript that would introduce you to that technology.

Hey Steven, Thanks for the help once again, I got it running after learning about local and session storage, I'm having another issue now, which I just can't quite seem to fix, can you please help me?

Here's the problem: https://teamtreehouse.com/community/this-works-on-the-computer-but-not-on-mobile

Steven Parker
Steven Parker
229,744 Points

I'd try, but I only have a PC for testing.

Oh okay, you won't be able to see that it is not working on PC, could you perhaps look through the code and tell me why it does not work on mobile, and how I can fix this.

Thanks so much, Sid

Steven Parker
Steven Parker
229,744 Points

I'd need to see the issue, and maybe tweak it a bit with the devtools to understand the cause. I'm going to have to leave this one to someone better equipped to look into it.