View Full Version : SSI 'include virtual' in a javascript random array

12-16-2007, 10:34 PM
(Here I am, once again jumping in the deep end and I don't even know where my water wings are, or how to put them on even if I had them. My knowledge of javascripting and programming is only enough to get myself in trouble.)

I'm trying to create a random array NOT using php but calling up files using SSI "include virtual".

<script type="text/javascript" language="javascript">
//Random Files
announcements = new Array(

// Pick a random file from the list

rnd.today=new Date();

function rnd()
rnd.seed = (rnd.seed*9301+49297) &#37; 233280;

return rnd.seed/(233280.0);

function rand(number)
return Math.ceil(rnd()*number);

document.write('<!--#include virtual="/commonfiles/' + announcements[rand(announcements.length)-1] + '" -->');


Not surprisingly, the document.write in the coding is throwing a "cannot complete this directive" error. Any idea if what I'm trying to do is even possible? (It is working just fine if I do not try to use SSI.)

I have searched as best I can here and by googling. I had hoped the following thread might have the answer but alas, I do not think so....

12-17-2007, 01:00 AM
Disclaimer: I'm no wizard with server-side coding. So take my advise with a grain of salt.

I think your problem is that the SSI works before the page is loaded. In your case, the page is loaded. I think you want ajax to grab the content after the page is loaded. Or use PHP to get the content before.

Btw, did you realize that there was a Math.random() function? It returns a decimal number from [0, 1).

12-17-2007, 12:55 PM
Thank you for your reply, Trinithis. No, I did not realize there was a Math.random() function... that will be useful, once I understand it.

It turns out on further googling that javascript and SSI cannot be used the way I was trying to do. Too bad....