Quotation & Single Quotes throw off my Javascript...
3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 19, 2010 (RSS)
By hordak - May 12, 2010
Hi I'm running a slideshow script that gets it's images/captions/etc. The script controller looks like this:
The Image Slideshow works great UNLESS I want to use Quotation marks or apostrophes in the info1 & info2 fields.
My Question: How do I get CMSB to publish "' as " ‘ ’?
<!-- STEP 2a: Display Uploads for field 'image_gallery' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: num, createdTime, tableName, fieldName, recordNum, preSaveTempId, filePath, filename, extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
<script type="text/javascript">
//<![CDATA[
window.addEvent('domready', function(){
// Load your images here
var data = {
<?php foreach ($pr_homepage_bannerRecords as $record): ?>
<?php foreach ($record['banner'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
'<?php echo $upload['filename'] ?>': { caption: '<div class="subhead_gold"><a href="<?php echo $record['link'] ?>"><?php echo $upload['info1'] ?></a></div><?php echo $upload['info2'] ?>' },
<?php else: ?>
'<?php echo $upload['filename'] ?>': { caption: '<div class="subhead_gold"><a href="<?php echo $record['link'] ?>"><?php echo $upload['info1'] ?></a></div><?php echo $upload['info2'] ?>' },
<?php endif ?>
<?php endforeach ?>
<?php endforeach ?>
'marauderPride.jpg': { caption: '<div class="subhead_gold"><a href="http://studentaffairs.centralstate.edu/document_details.php?Marauder-Pride-3">Marauder Pride</a></div>Honesty, hard work, caring and excellence define our pride.' }
};
// Initialize the Slideshow instance
var myShow = new Slideshow('show', data, { captions: true, controller: true, height: 215, hu: 'hp_includes/Slideshow/images/', width: 595 });
});
//]]>
</script>
<div id="show" class="slideshow" style="background: #ddd; border:0; padding:0;">
</div>
<?php if (!$pr_homepage_bannerRecords): ?>
<img src="hp_includes/Slideshow/images/01.jpg" alt="image 1" width="595" height="215" />
<?php endif ?>
<!-- STEP2a: /Display Uploads -->
The Image Slideshow works great UNLESS I want to use Quotation marks or apostrophes in the info1 & info2 fields.
My Question: How do I get CMSB to publish "' as " ‘ ’?
Re: [hordak] Quotation & Single Quotes throw off my Javascript...
By Chris - May 13, 2010
Hi hordak,
To escape quotes so you don't break your javascript, you can use addslashes():
I hope this helps. Please let me know if you have any questions.
To escape quotes so you don't break your javascript, you can use addslashes():
'<?php echo $upload['filename'] ?>': { caption: '<div class="subhead_gold"><a href="<?php echo $record['link'] ?>"><?php echo addslashes($upload['info1']) ?></a></div><?php echo addslashes($upload['info2']) ?>' },
<?php else: ?>
'<?php echo $upload['filename'] ?>': { caption: '<div class="subhead_gold"><a href="<?php echo $record['link'] ?>"><?php echo addslashes($upload['info1']) ?></a></div><?php echo addslashes($upload['info2']) ?>' },
I hope this helps. Please let me know if you have any questions.
All the best,
Chris
Chris
Re: [chris] Quotation & Single Quotes throw off my Javascript...
By hordak - May 19, 2010
Thanks Chris; that did it!
problem solved...
problem solved...