Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-16-2007, 09:34 PM   PM User | #1
llizard
Regular Coder

 
Join Date: Apr 2004
Location: Canada
Posts: 302
Thanks: 2
Thanked 0 Times in 0 Posts
llizard is an unknown quantity at this point
SSI 'include virtual' in a javascript random array

(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".

Code:
<script type="text/javascript" language="javascript">
//Random Files
announcements = new Array(
'test.txt',
'test2.txt',
'test3.txt'
);

// Pick a random file from the list

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd()
{
rnd.seed = (rnd.seed*9301+49297) % 233280;

return rnd.seed/(233280.0);
};

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


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

</script>
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....
http://www.codingforums.com/showthread.php?t=105055
llizard is offline   Reply With Quote
Old 12-17-2007, 12:00 AM   PM User | #2
Trinithis
Regular Coder

 
Join Date: Jun 2007
Location: USA
Posts: 527
Thanks: 26
Thanked 74 Times in 72 Posts
Trinithis will become famous soon enough
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).
Trinithis is offline   Reply With Quote
Old 12-17-2007, 11:55 AM   PM User | #3
llizard
Regular Coder

 
Join Date: Apr 2004
Location: Canada
Posts: 302
Thanks: 2
Thanked 0 Times in 0 Posts
llizard is an unknown quantity at this point
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....
llizard is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:39 PM.


Advertisement
Log in to turn off these ads.