PDA

View Full Version : Unterminated string constant



tripwater
Mar 21st, 2007, 02:24 PM
I am mixing php and JS in a script that uses mouseover tooltips.


I tried separating the strings to simplify the situation but I am still getting errors in IE6(only) this is working in FF and IE7 for some reason....

I was hoping someone could look at this and help me get these quotes and single ticks in line correctly :)

Here is my code



$star = replacePngTags('<img src=http://www.photogap.net/images/fav_icon.png width=25 height=28 border=0>');

if (!isset($_COOKIE["userfavs"]))
{
$value .= $star." <a href=\"http://www.mysite.php?fav=".$_SESSION["photographerID"]."\" onMouseover=\"ddrivetip('<br/>".$star." Click this link to add this photographer to your favorites. This feature uses cookies to remember your selections throughout the site. You must have cookies enabled in order for this feature to work.<br/><br/>', 300)\"; onMouseout=\"hideddrivetip()\">Add ".$_SESSION["FirstName"]." ".$_SESSION["LastName"]." to favorites</a><br/><br/>";


}


Just a brief explaination of some of the things you are looking at: replacePngTags() is a php function that takes a png24 image and makes it work in IE (simplified explaination). I have a small image that shows up in the tooltip that is of PNG type and has to be as the BG color of the tooltip can be modified and a gif looks like crap. The functions ddrivetip() and hideddrivetip() are the tooltip functions. I have all this in a php conditional so I assign the end result to a local var called $value.

I thought at first this may be a php question but anyone that works witha server side language should be able to help with this and I am getting JS errors.

THank you for any help with this.

Nightfire
Mar 21st, 2007, 02:29 PM
Looks like you had a semi-colon in the wrong place



<br/>', 300)\"; onMouseout

Move to


<br/>', 300);\" onMouseout

tripwater
Mar 21st, 2007, 02:36 PM
THank you very much for the reply. I made the change, however the problem still exists. I think the error is pointing to the quotes and single ticks and how I am escaping them....



a live example of what is happening is at Example (http://www.photogap.net/tripwater) You will notice beside the star, that everything is showing up on the page as it is broken(IE6 is the only place that it seems to be broken. If using IE7 or FireFox you will not see the problem). What should be showing is the star, and the text 'Add Tim Smith to favorites' and the tooltip show all the other stuff when you mouseover the link. You can mouse over the login link at the top to see the tooltip in action.

Thanks again for the reply.

Nightfire
Mar 21st, 2007, 02:52 PM
You've also got the semi-colon in the wrong place for the login links


galleries.<br/><br/>', 400)"; onMouseout="hideddrivetip()" class="a">Login

Probably won't make any difference, I can't see anything else wrong. But I'm not that good with JS anyway

tripwater
Mar 21st, 2007, 03:18 PM
Thanks again for the reply. Anyone else see the problem?

Kor
Mar 21st, 2007, 03:54 PM
XHTML needs a space before the end slash

<br />

But can you show us how the generated HTML code looks like? This is important for javascript

tripwater
Mar 21st, 2007, 04:03 PM
Well I will do the best I can as I know some of the quotes are closing the string prematurely.

Here is what gets generated from the php function and added into the string for the png image



<a href="http://www.photogap.net/common/favorites.php?fav=1" onMouseover="ddrivetip('<br /><img src="http://www.photogap.net/images/spacer.png" style="width: 25px; height: 28px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.photogap.net/images/fav_icon.png', sizingMethod=scale);" border=0> Click this link to add this photographer to your favorites. This feature uses cookies to remember your selections throughout the site. You must have cookies enabled in order for this feature to work.<br /><br />', 300);" onMouseout="hideddrivetip();">Add Tim Smith to favorites</a>

Still find it odd that it is working in IE7 and FF...

Nightfire
Mar 21st, 2007, 04:13 PM
I'd say it has to do with all them quotes you've got.


<img src=\"http://www.photogap.net/images/spacer.png\" style=\"width: 25px; height: 28px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'http://www.photogap.net/images/fav_icon.png\', sizingMethod=scale);\"

Not 100% sure which one's needed escaping, so did them all

tripwater
Mar 21st, 2007, 04:20 PM
I'd say it has to do with all them quotes you've got.

Not sure if you meant it to be funny but that cracked me up :)


THanks for the reply! Anyway, I am escaping those. In my original post, I handle it like so


$star = replacePngTags('<img src=http://www.photogap.net/images/fav_icon.png width=25 height=28 border=0>');

if (!isset($_COOKIE["userfavs"]))
{
$value .= $star." <a href=\"http://www.photogap.net/common/favorites.php?fav=".$_SESSION["photographerID"]."\" onMouseover=\"ddrivetip('<br />".$star." Click this link to add this photographer to your favorites. This feature uses cookies to remember your selections throughout the site. You must have cookies enabled in order for this feature to work.<br /><br />', 300);\" onMouseout=\"hideddrivetip();\">Add ".$_SESSION["FirstName"]." ".$_SESSION["LastName"]." to favorites</a><br /><br />";


}

Nightfire
Mar 21st, 2007, 04:27 PM
The code you just posted is showing the wrong code to what I've just escaped the quotes on for. The image I did it for is the spacer.png, not the fav_icon.png

It is in a function with it surrounded by single quotes ' ' and if you look where you're doing the ms filter, you're not escaping quotes there so it'll be ending it and causing an error from what I can see

glenngv
Mar 22nd, 2007, 05:57 AM
The generated code should look like this.

<a href="http://www.photogap.net/common/favorites.php?fav=1"
onMouseover="ddrivetip('<br /><img src=&quot;http://www.photogap.net/images/spacer.png&quot; style=&quot;width: 25px; height: 28px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'http://www.photogap.net/images/fav_icon.png\', sizingMethod=scale);&quot; border=&quot;0&quot;> Click this link to add this photographer to your favorites. This feature uses cookies to remember your selections throughout the site. You must have cookies enabled in order for this feature to work.<br /><br />', 300);"
onMouseout="hideddrivetip();">Add Tim Smith to favorites</a>