View Full Version : Newb question: Outputting quotes in javascript?

01-05-2012, 04:40 PM
I'm trying to insert a title and a body into a Google maps window through PHP. The body could contain double or single quotes. How do I output these so that they don't break the script?

Relevant code:

$('#map_canvas').gmap('openInfoWindow', { 'content': '<strong><?php echo $m->marker->Title; ?></strong><br /><?php echo $m->marker->Body; ?><?php echo '<a href="./marker_info.php?id='.$m->marker->Nid.'"></a>' ?><br /><a id="m_location" href="#" data-role="button" data-icon="search" onclick="$.mobile.silentScroll(500);"></a>'}, this);

Philip M
01-05-2012, 04:51 PM
Escape the quotes (to ensure they are interpreted as a literal).

\" or \'

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.