Mohamed  Kira Mohamed Kira - 3 months ago 32
Javascript Question

Uncaught SyntaxError: missing, ) after argument list

im bulding a search box for movies using an API
any time onkeyup event takes place a function is called which in turn prepare an ajax and display the responsed json in li tags.
of course it displays 20 results i want to be able to store the result the user clicked on and displayed on div id="target"
here is my code:

http://jsfiddle.net/bkj2z39y/

every thing is working except the clicking

function func(str) {

$('#here').html('');
document.getElementById("here").style.border = "0px";
$('#movie').val('');
alert(str);

$('#target').html(str);
console.log(str);

}


i have tried several methods, this last one gives me an error

Uncaught SyntaxError: missing ) after argument list

Answer

Line 34 in Your fiddle. You pass string without quote. Change it to:

title += '<div id="element" onclick="func(\'' + ajax.results[i].original_title + '\')"><img src="http://image.tmdb.org/t/p/w500' + ajax.results[i].poster_path + '" height="50" width="40" id="poster"  class="img-responsive img-thumbnail"';

Working code: http://jsfiddle.net/bkj2z39y/1/