Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Error: 'missing ) after argument list"

I am making an image for my webpage through javascript like so:

photoHTMLString = '<li class = "SliderPhoto"><img src =  "' + ImageArray[x].src_small + '" size = "thumb" onclick = "ShowImagePopUP(' + ImageArray[x].src_big + ')" class = "FacebookSliderPhoto"/></li>';

Whenever I try and click a photo go into ShowImagePopUP I get this error:

missing ) after argument list
[Break On This Error] ShowImagePopUp(http://a8.sph...389_84095143389_5917147_2636303_n.jpg)

It doesn't look like I am missing any ')'s so I am lost on the error. Any suggestions?

like image 722
Soatl Avatar asked May 12 '11 18:05

Soatl


People also ask

How do I fix SyntaxError missing after argument list?

The "SyntaxError: missing ) after argument list" occurs when we make a syntax error when calling a function, e.g. forget to separate its arguments with a comma. To solve the error make sure to correct any syntax errors in the arguments list of the function invocation. Copied!

What does missing after argument list?

The JavaScript exception "missing ) after argument list" occurs when there is an error with how a function is called. This might be a typo, a missing operator, or an unescaped string.

What is an argument list JavaScript?

arguments is an Array -like object accessible inside functions that contains the values of the arguments passed to that function.


2 Answers

try

photoHTMLString = '<li class = "SliderPhoto"><img src =  "' 
                + ImageArray[x].src_small 
                + '" size = "thumb" onclick = "ShowImagePopUP(\"' 
                + ImageArray[x].src_big + '\")" class = "FacebookSliderPhoto"/></li>';

should do the trick and solve your problem leaving intact the uglyness of you code

A function like this one should be a bit readable and ready to use...

function slideElement(image){
    var li=document.createElement('li');
    var img=document.createElement('img');
    li.appendChild(img);
    li.setAttribute('class','SliderPhoto');
    img.setAttribute('class','FacebookSliderPhoto');
    img.setAttribute('size', 'thumb');
    img.setAttribute('src', image.src_small);
    img.setAttribute('onclick', function(){showImagePopUP(image.src_big);});

    return li;
}
like image 191
Eineki Avatar answered Oct 20 '22 18:10

Eineki


You need to wrap the contents of ShowImagePopUP in quotes:

"ShowImagePopUp(\'' + ImageArray[x].src_big + '\')"

Which should render as:

ShowImagePopUp('http://a8.sph...389_84095143389_5917147_2636303_n.jpg')
               ^ note the quote here

Example: http://jsfiddle.net/V23J6/1/

like image 38
mellamokb Avatar answered Oct 20 '22 19:10

mellamokb