Jump to content

Inserting Image


rockinaway

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/83977-inserting-image/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/83977-inserting-image/#findComment-427368
Share on other sites

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 :D

Link to comment
https://forums.phpfreaks.com/topic/83977-inserting-image/#findComment-427441
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.