...

View Full Version : Need code fix - Include file within Javascript



idesign123
08-22-2008, 03:08 AM
The following 'random content' script that is working great...



//RANDOM CONTENT
function hometext() {
var count = 3;
var r = Math.ceil(Math.random() * count);
if (r == 1) return "Mary had a Little Lamb";
if (r == 2) return "Humpty Dumpty";
if (r == 3) return "Little Jack Horner">";
}

// End -->


The problem is that I want to make the text editable by the client.
I'm using 'include' files throughout the site, so I would love to change it to something like this...



//RANDOM CONTENT
function hometext() {
var count = 3;
var r = Math.ceil(Math.random() * count);
if (r == 1) return "<!--#include virtual="include/hometext1.html" -->";
if (r == 2) return "<!--#include virtual="include/hometext2.html" -->";
if (r == 3) return "<!--#include virtual="include/hometext3.html" -->">";
}

// End -->


This breaks the Javascript (I'm assuming because it has illegal characters in it).

Is there a code change I could make that would make it work? Or are 'includes' not allowed here?

oesxyl
08-22-2008, 03:58 AM
try to escape '"' as '\"':


//RANDOM CONTENT
function hometext() {
var count = 3;
var r = Math.ceil(Math.random() * count);
if (r == 1) return "<!--#include virtual=\"include/hometext1.html\" -->";
if (r == 2) return "<!--#include virtual=\"include/hometext2.html\" -->";
if (r == 3) return "<!--#include virtual=\"include/hometext3.html\" -->\">";
}

// End -->


but I don't think it work with ssi

regards

idesign123
08-22-2008, 05:41 AM
Thanks for taking a look.

* And for reminding me of the 'escape' for quotes - I'm still pretty new and forgot about that!

I think I have an idea for another way to do this. Not quite as easy as this would have been, but it'll work.

Best wishes.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum