1

I am trying to pass a movie id to the url when a movie is clicked on, and retrieve the movie id in the destination page. I know forms do this by default, but I want to accomplish this with an anchor element.

So for example i have this homepage url:

http://127.0.0.1:5500/client/index.html

I click on a movie on the homepage and the movie has an anchor tag which redirects to a different file:

http://127.0.0.1:5500/client/views/movies.html

The movie has an id that I want to be available in the /movies.html page, and the movies url should look something like this:

http://127.0.0.1:5500/client/views/movies.html?movieId=1234

How would I accomplish this using javascript?

Here is the html:

 <div class="card">
    <a href="${'/client/views/movies.html'}" data-src="1234" >
        <img class="img-size" src="${poster_image}" alt="">
    </a>
    <div class="card-body">
       <h6 class="card-title"> ${el.title}</h6>
          <p>${el.release_date}</p>
    </div>
 </div>

1
  • 3
    You can add the query param in href tag itself Commented Jun 28, 2020 at 21:00

1 Answer 1

3

Just add the desired parameter in the anchor tag href itself like this:

 <div class="card">
    <a href="${'/client/views/movies.html?movieId=1234'}" data-src="1234" >
        <img class="img-size" src="${poster_image}" alt="">
    </a>
    <div class="card-body">
       <h6 class="card-title"> ${el.title}</h6>
          <p>${el.release_date}</p>
    </div>
 </div>
Sign up to request clarification or add additional context in comments.

1 Comment

Wow why didn't i think of that. I thought it was going to be complicated and didn't even realize i could do that. This is what fixed it. ` <a href="${/client/views/movies.html?movieId=${el.id}}`. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.