0

I keep getting a "missing ) after argument list" (on line 1) when debugging my javascript with firebug. I don't know what is wrong as it seems all parentheses are there.

The function is supposed to place an image that can be clicked to open a lightbox in the div with id "bigPic".

Here's the relevant code:

<script type="text/javascript">
function addContent(divId,filePath,comment) {
document.getElementById(divId).innerHTML = "<div align=\"center\"><a href="+filePath+" title="+comment+" rel=\"lightbox\"><img src="+filePath+" alt="+comment+" style=\"max-height:270px;max-width:410px;\"/></a></div><div id="+comment+" align=\"center\"  style=\"font-family:Verdana;margin-top:-13px;color:white;background-color:#07396B;\"><p>"+comment+"</p></div>&nbsp;";
}
</script>
...
<div width="420px" height="320px" id="bigPic" name="bigPic">
<img src="http://www.villa-gloria-katouna.com/Pool%20viewsmall.JPG" />
</div>
...
echo "<div align=\"center\" style=\"display:inline; overflow:hidden;\"><img src=\"pics/$file\" style=\"cursor:pointer;cursor:hand;\" alt=\"$file\" height=\"30px\" width=\"30px\" onclick=\"addContent('bigPic', $file, $comment);\"/></a></div>&nbsp;";
4
  • 1
    That code is fine. Your error is somewhere else. Show your full code. Commented Dec 26, 2011 at 22:20
  • 1
    @Xeon06 "Fine" is a very...subjective word. Commented Dec 26, 2011 at 22:22
  • @Zirak as in, there are no bugs in it. But I might have been wrong, Pointy caught something I hadn't noticed. Commented Dec 26, 2011 at 22:23
  • What's up with the echo? Commented Dec 26, 2011 at 22:26

4 Answers 4

3

I think you forgot quote characters around "$file" and "$comment" in the "onclick" handler code.

     ... onclick=\"addContent('bigPic', '$file', '$comment');\" ...

I don't know PHP so that may or may not be the way to get quotes in the "onclick" string, but they need to be there. Otherwise if the comment is "hello world" that'll expand to

     ... onclick="addContent('bigPic', whatever-$file-is, hello world)" ...

which is clearly incorrect.

Sign up to request clarification or add additional context in comments.

1 Comment

echo "<div align=\"center\" style=\"display:inline; overflow:hidden;\"><img src=\"pics/" . $file . "\" style=\"cursor:pointer;cursor:hand;\" alt=\"" . $file . "\" height=\"30px\" width=\"30px\" onclick=\"addContent('bigPic', 'pics/" . $file . "', '" . $comment . "');\"/></a></div>&nbsp;"; did the trick, thx!
1

try

onclick=\"addContent('bigPic', '$file', '$comment');\"

instead of

onclick=\"addContent('bigPic', $file, $comment);\"

Comments

0

Single quotes as wrapper of string istead double prevent to writing backslashes. This faciliate now and in the future:)

'<div align="center">'

Comments

0

Change your script code as:

<script type="text/javascript">
function addContent(divId,filePath,comment) {
document.getElementById(divId).innerHTML = "<div align=\"center\"><a href=\"" + filePath + "\" title=\"" + comment + "\" rel=\"lightbox\"><img src=\"" + filePath + "\" alt=\"" + comment + "\" style=\"max-height:270px;max-width:410px;\"/></a></div><div id=\"" + comment + "\" align=\"center\"  style=\"font-family:Verdana;margin-top:-13px;color:white;background-color:#07396B;\"><p>\"" + comment + "\"</p></div>&nbsp;";
}
</script>

Also change your echo to

echo "<div align=\"center\" style=\"display:inline; overflow:hidden;\"><img src=\"pics/" . $file . "\" style=\"cursor:pointer;cursor:hand;\" alt=\"" . $file . "\" height=\"30px\" width=\"30px\" onclick=\"addContent('bigPic', '" . $file . "', '" . $comment . "');\"/></a></div>&nbsp;";

1 Comment

this still gives me the same errors, I will post my full code

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.