rockinaway Posted January 1, 2008 Share Posted January 1, 2008 I am trying to insert an image using a Javascript function, but I get the 'unterminated string literal' error. The code I am using is: javascript:doInsImg('<img src="http://example.com/tongue.gif" />'); But I get the error (from Firebug): unterminated string literal javascript:doInsImg('<img src= Line 1 What do I do? It has something to do with the double quotes I think (").. any help? Quote Link to comment Share on other sites More sharing options...
duclet Posted January 1, 2008 Share Posted January 1, 2008 What is this "doInsImg" function? I don't recall ever seeing it. Anyway, from the looks of things, I assume this is being called within a HTML tag such as <a href="javascript: dosomething();">Do Something</a> right? If that is the case, I can guess on what the problem is. You see that double quotes before the http://?, that is ending the string of the attribute tag. You will need to escape it so you'll want that line to look something like: javascript:doInsImg('<img src=\"http://example.com/tongue.gif\" />'); Of course, I would need to see more of the source code if that doesn't work. Quote Link to comment Share on other sites More sharing options...
rockinaway Posted January 1, 2008 Author Share Posted January 1, 2008 I have tried that already, it doesn't work either. I forgot to mention that this is in a PHP file And the HTML its are quoted in.. like they are supposed to.. My InsImg function is: function doInsImg(img { box.open(); box.write(img); box.close(); } box is defined earlier, and works with other functions, so that isn't causing the problem Hope you can help Quote Link to comment Share on other sites More sharing options...
rockinaway Posted January 1, 2008 Author Share Posted January 1, 2008 Ok, I replaced the double quotes with single quotes and escaped them with \... But now I have another problem.. I get: missing ) after argument list I have tried escaping the closing /> bye doing \/>, but that doesn't work... Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 1, 2008 Share Posted January 1, 2008 function doInsImg(img) { box.open(); box.write(img); box.close(); } you were missing the "close parenthesis" around your functions parameter. Quote Link to comment Share on other sites More sharing options...
rockinaway Posted January 1, 2008 Author Share Posted January 1, 2008 Doesn't help, (missed that off by accident when copying to here!) Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 1, 2008 Share Posted January 1, 2008 well that is the only close parenthesis missing in the code you provided here. you will have to post your entire/full code; so I can take a look at it, if you want me to help you further with this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.