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 09-01-2006, 11:34 PM   PM User | #1
camalex
New to the CF scene

 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
camalex is an unknown quantity at this point
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?
camalex is offline   Reply With Quote
Old 09-02-2006, 10:37 AM   PM User | #2
mic2100
Regular Coder

 
mic2100's Avatar
 
Join Date: Feb 2006
Location: Scunthorpe
Posts: 562
Thanks: 15
Thanked 28 Times in 27 Posts
mic2100 is on a distinguished road
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>
mic2100 is offline   Reply With Quote
Old 09-02-2006, 06:25 PM   PM User | #3
camalex
New to the CF scene

 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
camalex is an unknown quantity at this point
Uhh, didn't work... Gahh, what's wrong? I'm clueless....
camalex is offline   Reply With Quote
Old 09-02-2006, 07:29 PM   PM User | #4
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
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
__________________
Get Firefox Now
rafiki 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 05:34 PM.


Advertisement
Log in to turn off these ads.