I am having major trouble trying to fix a bug within my code. Basically I have this button that when clicked will send two parameters to a function. The first parameter is a TV show's ID and the second is the TV show's name. Now this works unless I click the button and it tries to send a TV show name like Grey's Anatomy due to the single quotation.
Is there any way I can make use of the js replace function with this?
The line of code that I am having trouble with is here:
<a onclick="watchedShow('${showArr[i].imdbID}','${showArr[i].Title}'" class="btn btn-primary" href="#"></a>
Where showArr is an array of show names such as Game of Thrones and Grey's Anatomy. The error I am getting is: SyntaxError: missing ) after argument list. This happens when showArr[i].Title is Grey's Anatomy which I believe is due to the single quotation in the string. Any help would be appreciate.
Thanks!
The rest of my code, if needed is here:
var showArr = res.data.Search;
var output = '';
for(i = 0; i < showArr.length; i++) { //loops through the results and puts the show names in an array.
output += `
<div class="col-4">
<div class="well text-center">
<img src="${showArr[i].Poster}" alt="Image not found" onerror="this.src='image-not-found.gif';" height="450" width="350">
<h5>${showArr[i].Title}</h5>
<a onclick="setShowID('${showArr[i].imdbID}')" class="btn btn-primary" href="showdetails.html">Show Details</a>`;
if(sessionStorage.getItem('username')) {
output +=`<a onclick="watchedShow('${showArr[i].imdbID}','${showArr[i].Title}'" class="btn btn-primary" href="#"></a>
</div>
</div>`;
}
else {
output += ` </div>
</div>`;
}
}
$('#shows').html(output);
}