1

I am a beginner in JavaScript and I am facing a problem while using the onclick event Can you please help me?

movie1.innerHTML = `
                <img src="${IMG_URL + poster_path}" alt="Poster">
                <p class="title">${title}</p>
                <span>Rating : ${vote_average}</span>
                <div class="summary">
                    <p>${overview}</p>
                </div>
              <button class="watchbtn" onclick="passname(${title})" >Watch</button>
            </div>
        `;

In the Above code I get an error which shows "Uncaught SyntaxError: missing ) after argument list"

8
  • the error seems not to be in this code snippet, can you share a little bit more code? Commented Mar 27, 2022 at 12:51
  • What is in the title variable? Commented Mar 27, 2022 at 12:53
  • @LasseLenting the error occurs when I pass the $(title) parameter in the onclick event Commented Mar 27, 2022 at 12:53
  • 1
    @ManavJoshi what is it's contents? It should be: passname('${title}') Commented Mar 27, 2022 at 12:55
  • 1
    @NickParsons Thanks a lot, the error has been resolved, Thanks a bunchhhh Commented Mar 27, 2022 at 12:56

1 Answer 1

2

Try this:

movie1.innerHTML = `
                <img src="${IMG_URL + poster_path}" alt="Poster">
                <p class="title">${title}</p>
                <span>Rating : ${vote_average}</span>
                <div class="summary">
                    <p>${overview}</p>
                </div>
              <button class="watchbtn" onclick="passname('${title}')" >Watch</button>
            </div>
        `;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.