Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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) &#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] + '" -->');
    
    </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

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    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

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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....


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •