- Impact
- 0
Hey everyone, I'm fairly new (and I mean, completely new) to Javascript programming. I have a tiny little bit of experience in other languages (most predominantly html/css) and have come to a point where I can't seem to find an answer anywhere for this.
What I'm hoping to do is have a Javascript read from a custom array (that I would create) using the 11 character codes for youtube videos, randomly select one such code from that array, and use it to display an embedded video, in effect selecting and displaying a random video from a custom created list. I'm looking to do this without resorting to PHP.
So far I've had no luck, and I will provide here the code for you to see.
Here is the Javascript at its source;
http://yourjavascript.com/26101752210/rndvid.js
and for those of you who would prefer to read it in the forum, here it is;
(I will note I modified but did not write this code!)
Here is the HTML that I place on the page to attempt to have the video displayed;
Does anything immediately pop out as incorrect? Are there any helpful suggestions that can be provided (Besides the "use PHP" default response I received on a few other forums?
All help and advice is greatly appreciated, thank you!
What I'm hoping to do is have a Javascript read from a custom array (that I would create) using the 11 character codes for youtube videos, randomly select one such code from that array, and use it to display an embedded video, in effect selecting and displaying a random video from a custom created list. I'm looking to do this without resorting to PHP.
So far I've had no luck, and I will provide here the code for you to see.
Here is the Javascript at its source;
http://yourjavascript.com/26101752210/rndvid.js
and for those of you who would prefer to read it in the forum, here it is;
Code:
function randomVideo(){
//format for calling pop up window
vid = new Array();
vid[0] = 'X3iFhLdWjqc';
vid[1] = 'ADC3SLx6HV8';
var ranNum = Math.floor(Math.random() * vid.length);
var movielink;
movielink = "http://www.youtube.com/v/" + vid[ranNum] + "&rel=1";
var mainlink = "";
mainlink = "<object width='425' height='355'>";
mainlink = mainlink + "<param name='wmode' value='transparent'></param>";
mainlink = mainlink + "<embed src='" + movielink + "' type='application/x-shockwave-flash' wmode='transparent' width='425' height='355'></embed>";
mainlink = mainlink + "</object>";
document.getElementById('movietext').innerHTML = mainlink;
document.write(mainlink);
return false;
}
(I will note I modified but did not write this code!)
Here is the HTML that I place on the page to attempt to have the video displayed;
Code:
<script type="text/javascript" src="http://yourjavascript.com/26101752210/rndvid.js">
randomVideo();
</script>
Does anything immediately pop out as incorrect? Are there any helpful suggestions that can be provided (Besides the "use PHP" default response I received on a few other forums?
All help and advice is greatly appreciated, thank you!