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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Random Goolge Video...

    Basically, I have multiple Google videos... but I only want to display one at a time on my site. So, the best way to do this is have the one displayed to be randomly picked... but I have no clue how to do this.

    I do know the embed html is

    <embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=-4203295387902104151&hl=en"></embed>

    The bolded part is the part that needs to be either

    4203295387902104151
    8909400237855893347
    1446340990435255030

    One of those three numbers. I know I CAN do it, just no clue what I'm doing enough to be able to do it. Help?

  • #2
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    here this makes a random number and using a switch statement it chooses one of the videos

    PHP Code:
    <script language="javascript" type="text/javascript">
    function 
    get_random(n)
    {
        var 
    ranNum = (Math.floor(Math.random()* ) );
        
        var 
    docId
        
        
    switch(ranNum)
        {
        

                              case 
    1:
            
                
    docId 4203295387902104151;
                break;
            
            case 
    2:
            
                
    docId 8909400237855893347;
                break;
            
            case 
    3:
            
                
    docId 1446340990435255030;
                break;            
        
        }
        
        
    document.getElementById("VideoPlayback").src "http://video.google.com/googleplayer.swf?docId=-" docId "&hl=en";
    }
    </script> 
    Code:
    <!-- change this number depending on the amount of cases you have in the switch statement (reflects the amount of movies you want to display-->
    
    <body onLoad="get_random(3)">
    <embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src=""></embed>
    
    </body>

  • #3
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Uhh, didn't work... Gahh, what's wrong? I'm clueless....

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    the url chosen during the random needs to be saved into a var so u can write the var into the scr in the embed tag


  •  

    Posting Permissions

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