/    Sign up×
Community /Pin to ProfileBookmark

can i put in this line prefix

[CODE]document.getElementById(“youtube”).src = vids[num];[/CODE]

to be something like this ?

[CODE]document.getElementById(“http://www.youtube.com/embed/” + “youtube”).src = vids[num];[/CODE]

thank you in advance ?

to post a comment
JavaScript

25 Comments(s)

Copy linkTweet thisAlerts:
@AbeWayerMar 28.2012 — First: don't write "I need help" like title of the post.

Use something like the description of the problem.

Second: explain the problem.

What does the code should do?

What do you want do?

Thanks
Copy linkTweet thisAlerts:
@ludaludiauthorMar 28.2012 — i just want to put http://www.youtube.com/embed/ in front of "youtube_code"
Copy linkTweet thisAlerts:
@Gray1989Mar 29.2012 — [CODE]document.getElementById("http://www.youtube.com/embed/" + "youtube").src = vids[num];[/CODE][/QUOTE]

You should go through a basic JavaScript DOM tutorial then lookup references using Google for functions like getElementById, and maybe also html definitions for things like "elements". An element is an HTML tag on a webpage that allows for more HTML. Basically like an HTML code seperator or even object like a textbox or button. A URL like "http://www.whatever.com/page" is NOT an element. It is a reference to a new page. Please provide more code along with a description of what you need to accomplish.
Copy linkTweet thisAlerts:
@ludaludiauthorMar 30.2012 — i find this code on this site ...
[CODE]
<script type="text/javascript">
function rand ( n )
{
return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

var vids = new Array ( );
vids[0] = "http://www.youtube.com/embed/aF4M0JtoIPk"; ">>>>SONG NAME<<<<"
vids[1] = "http://www.youtube.com/embed/KMxWhovYfzc"; ">>>>SONG NAME<<<<"

function pick_vid ( )
{
var numberOfImages = 2;
var num = rand(numberOfImages)-1;

document.getElementById("random_youtube_vid").src = vids[num];
document.getElementById("LINK").innerHTML = vids[num];
}
</script>

<script type="text/javascript">window.onload=pick_vid;</script>
<iframe id="random_youtube_vid" width="250" height="200" frameborder="0" allowfullscreen></iframe>

<div id="LINK"></div>
[/CODE]




so i just want to add some function "SONG NAME" in line [CODE]<div id="LINK"></div> [/CODE] instead of showing url from youtube video
Copy linkTweet thisAlerts:
@PadonakMar 31.2012 — [CODE]...
var vids=[
["http://www.youtube.com/embed/aF4M0JtoIPk", ">>>>SONG NAME 1<<<<"],
["http://www.youtube.com/embed/KMxWhovYfzc", ">>>>SONG NAME 2<<<<"]
];

function pick_vid ( )
{
var numberOfImages = 2;
var num = rand(numberOfImages)-1;

document.getElementById("random_youtube_vid").src = vids[num][0];
document.getElementById("LINK").innerHTML = vids[num][1];
}
...[/CODE]
Copy linkTweet thisAlerts:
@ludaludiauthorMar 31.2012 — ty so much , so pro !!!!

i have one more question to ask about this code ?
[CODE]
var vids=[
["aF4M0JtoIPk", ">>>>SONG NAME 1<<<<"],
["KMxWhovYfzc", ">>>>SONG NAME 2<<<<"]
];
[/CODE]



can i remove this part from script "http://www.youtube.com/embed/" and put it in iframe ?

for exemple <iframe id="http://www.youtube.com/embed/"+"random_youtube_vid"></iframe> or something like that ?
Copy linkTweet thisAlerts:
@PadonakMar 31.2012 — [CODE]...
var vids=[
["aF4M0JtoIPk", ">>>>SONG NAME 1<<<<"],
["KMxWhovYfzc", ">>>>SONG NAME 2<<<<"]
];

function pick_vid ( )
{
var numberOfImages = 2;
var num = rand(numberOfImages)-1;
[COLOR="red"]var prefix = "http://www.youtube.com/embed/";[/COLOR]

document.getElementById("random_youtube_vid").src = [COLOR="Red"]prefix+[/COLOR]vids[num][0];
document.getElementById("LINK").innerHTML = vids[num][1];
}
...[/CODE]
Copy linkTweet thisAlerts:
@ludaludiauthorMar 31.2012 — that was fast ... ? thank you so much , this will help me better understand jquery scripting !!!!

and i just add suffix xD for auto play ....

<i>
</i> var numberOfImages = 2;
var num = rand(numberOfImages)-1;

var prefix = "http://www.youtube.com/embed/"; <br/>
[COLOR="Red"]var suffix = "?rel=0&amp;am;autoplay=1";[/COLOR]

document.getElementById("random_youtube_vid").src = prefix+vids[num][0][COLOR="Red"]+suffix[/COLOR];
document.getElementById("LINK").innerHTML = vids[num][1];
Copy linkTweet thisAlerts:
@PadonakMar 31.2012 — good to hear ))
Copy linkTweet thisAlerts:
@ludaludiauthorApr 01.2012 — is there any chance to add this code next button ?

current song + 1 = next song ... something like that

and when number is over max go back to first song
Copy linkTweet thisAlerts:
@PadonakApr 01.2012 — [CODE]<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>123</title>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<style type="text/css">
body{text-align:center;font-family:Verdana,Arial;font-size:11px;background-color:#fff;color:#000;padding:0px;margin:30px;}
a:link,a:active,a:visited{color:#000;background-color:transparent;font-weight:bold;letter-spacing:1px;text-decoration:none;}
a:hover{color:Crimson;background-color:transparent;font-weight:bold;letter-spacing:1px;text-decoration:none;}
div{margin-top:5px;padding:20px;}
b{color:Crimson;}
.cur{color:Green;background-color:transparent;}
.tot{color:Darkorange;background-color:transparent;}
</style>
<script type="text/javascript">
//we can use this synthax instead of var1=...;var2=...; etc.
var prefix="http://www.youtube.com/embed/",
suffix="?rel=0&am;autoplay=1",
vids=[
["aF4M0JtoIPk", "Reborn - Amina Khan"],
["KMxWhovYfzc", "New Muslims in Europe"],
["1eUOgD2Y9c8", "My Reversion To Islam"],
["hp0Wn8BoKyA", "Islam Saved My Life"]
];
function randomNumber(m,n){m=parseInt(m);n=parseInt(n);return Math.floor(Math.random()*(n-m+1))+m;}
function pick_vid(){
var num=(typeof(pick_vid.arguments[0])!='undefined')?pick_vid.arguments[0]:randomNumber(0,vids.length-1);
if(num==vids.length){num=0;}
/*the above means that you can pass the number of desirable song into the function
but if no any arguments passed the function picks a random song*/
$('#youtube_vid').attr('src',prefix+vids[num][0]+suffix);
$("#descr").html(vids[num][1]);
var ending='';
switch(num+1){
case 1:ending='st';break;
case 2:ending='nd';break;
case 3:ending='d';break;
default:ending='th';
}
$('#counter').html('<b class="cur">'+(num+1)+'-'+ending+'</b> of <b class="tot">'+vids.length+'</b> videos is being played now<br /><br /><a href="#null" onclick="pick_vid('+(num+1)+')">play next</a>');
}
$(document).ready(function(){
//just for fun
var h2=function(){$('h2:has(b:contains("JQuery"))').fadeOut('slow',function(){$(this).remove();});}
setTimeout(h2,1000);
});
</script>
</head>
<body>
<center>
<iframe id="youtube_vid" width="250" height="200" frameborder="0" allowfullscreen></iframe>
<div id="descr">song name goes here</div>
<div id="counter"><h2>Ok let's use <b>JQuery</b> as we went so far ;-)</h2></div>
<div><a href="#null" onclick="pick_vid()">random song</a></div>
</center>
</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@ludaludiauthorApr 01.2012 — :eek:

we know too much...we went so far ?

this is my last question in this topic ... ty so much ... you give me good player script for my forum ? its so cool

when user load this script, can random song start autoplay without clicking on random button ?
Copy linkTweet thisAlerts:
@PadonakApr 01.2012 — just replace
[CODE]$(document).ready(function(){
//just for fun
var h2=function(){$('h2:has(b:contains("JQuery"))').fadeOut('slow',function(){$(this).remove();});}
setTimeout(h2,1000);
});[/CODE]


with
[CODE]$(document).ready(function(){
pick_vid();
});[/CODE]


and of course remove that [B]h2[/B] tag from the markup - it was just for fun
Copy linkTweet thisAlerts:
@ludaludiauthorApr 01.2012 — i made previous song buttun ?

works good too ?

[CODE]
<script type="text/javascript">
var prefix="http://www.youtube.com/embed/", suffix="?rel=0&am;autoplay=1"; //we can use this synthax instead of var1=...;var2=...; etc.

vids=[
["aF4M0JtoIPk", "Reborn - Amina Khan"],
["KMxWhovYfzc", "New Muslims in Europe"],
["1eUOgD2Y9c8", "My Reversion To Islam"],
["hp0Wn8BoKyA", "Islam Saved My Life"]
];

function randomNumber(m,n){
m=parseInt(m);n=parseInt(n);return Math.floor(Math.random()*(n-m+1))+m;
}

function pick_vid(){
var num=(typeof(pick_vid.arguments[0])!='undefined')?pick_vid.arguments[0]:randomNumber(0,vids.length-1);
if(num==vids.length){num=0;}
[COLOR="Red"]if (num==-1){num+=vids.length;}[/COLOR]


$('#youtube_vid').attr('src',prefix+vids[num][0]+suffix);
$("#descr").html(vids[num][1]);
var ending=' ';
switch(num+1){
case 1:ending='st';break;
case 2:ending='nd';break;
case 3:ending='d';break;
default:ending='th';
}
$('#counter').html('<b class="cur">'+(num+1)+'-'+ending+'</b> of <b class="tot">'+vids.length+'</b> videos is being played now<br /><a href="#null" onclick="pick_vid('+(num+1)+')">NEXT SONG</a>[COLOR="Red"]<a href="#null" onclick="pick_vid('+(num-1)+')">PREV SONG</a>[/COLOR]');
}

$(document).ready(function(){pick_vid();}); //autoplay random start
</script>

<iframe id="youtube_vid" width="250" height="200" frameborder="0" allowfullscreen></iframe>
<div id="descr">SONG TITLE</div><div id="counter"></div><div><a href="#null" onclick="pick_vid()">RANDOM SONG</a></div>

[/CODE]
Copy linkTweet thisAlerts:
@ludaludiauthorApr 02.2012 — is there any chance to line
[CODE]<a href="#randomize" onclick="pick_vid()"><img src="http://i43.servimg.com/u/f43/11/33/28/68/button10.png" title="Random Song"></a>[/CODE]
fade out and then after few minutes show up ?

because when someone start to click that button like crazy ? u get captcha on youtube

btw your script works perfectly and currently 127 songs in playlist ? ty
Copy linkTweet thisAlerts:
@PadonakApr 02.2012 — place these lines before the pick_vid() function closing bracket
[CODE]var x=function(){$('a[href*=randomize]').fadeIn('fast');}
$('a[href*=randomize]').fadeOut('normal',function(){setTimeout(x,3000);});[/CODE]
Copy linkTweet thisAlerts:
@ludaludiauthorApr 02.2012 — [CODE]
vids=[
["vcZlR05X0m4", "Nile - Annihilation of the wicked"],
["eZra-mVOfc8", "Mortician - Hell on Earth"],
["j8DHnPP7zpg", "Infernal Revulsion - Trapped In Concrete, Seek Insanity"],
["IBsWHpbJAm0", "Abominable Putridity - Sphacelated Nerves"]
];

var prefix="http://www.youtube.com/embed/", suffix="?rel=0&am;autoplay=1"; //we can use this synthax instead of var1=...;var2=...; etc.

function randomNumber(m,n){m=parseInt(m);n=parseInt(n);return Math.floor(Math.random()*(n-m+1))+m;}

[COLOR="Red"]var x=function(){$('a[href*=randomize]').fadeIn('fast');}
$('a[href*=randomize]').fadeOut('normal',function(){setTimeout(x,3000);});[/COLOR]

function pick_vid(){
var num=(typeof(pick_vid.arguments[0])!='undefined')?pick_vid.arguments[0]:randomNumber(0,vids.length-1);
if(num==vids.length){num=0;}
if(num==-1){num+=vids.length;}

$('#youtube_vid').attr('src',prefix+vids[num][0]+suffix);
$("#descr").html(vids[num][1]);
var ending=' ';

$('#counter').html('<b class="cur">'+(num+1)+'</b> of <b class="tot">'+vids.length+'</b>');
$('#next').html('<a href="#null" onclick="pick_vid('+(num+1)+')">NEXT SONG</a>');
$('#prev').html('<a href="#null" onclick="pick_vid('+(num-1)+')">PREV SONG</a>');
}

$(document).ready(function(){pick_vid();}); //autoplay random start
[/CODE]


i tried like this , don't work :S
Copy linkTweet thisAlerts:
@PadonakApr 02.2012 — [B][U]before[/U] the [COLOR="Red"]pick_vid(){[/COLOR] function closing bracket[COLOR="red"] [COLOR="SeaGreen"]--->[/COLOR] }[/COLOR][/B]
Copy linkTweet thisAlerts:
@ludaludiauthorApr 02.2012 — [CODE]
vids=[
["vcZlR05X0m4", "Nile - Annihilation of the wicked"],
["eZra-mVOfc8", "Mortician - Hell on Earth"],
["j8DHnPP7zpg", "Infernal Revulsion - Trapped In Concrete, Seek Insanity"],
["IBsWHpbJAm0", "Abominable Putridity - Sphacelated Nerves"]
];

var prefix="http://www.youtube.com/embed/", suffix="?rel=0&am;autoplay=1"; //we can use this synthax instead of var1=...;var2=...; etc.

function randomNumber(m,n){m=parseInt(m);n=parseInt(n);return Math.floor(Math.random()*(n-m+1))+m;}

function pick_vid(){
var num=(typeof(pick_vid.arguments[0])!='undefined')?pick_vid.arguments[0]:randomNumber(0,vids.length-1);
if(num==vids.length){num=0;}
if(num==-1){num+=vids.length;}

$('#youtube_vid').attr('src',prefix+vids[num][0]+suffix);
$("#descr").html(vids[num][1]);
var ending=' ';

$('#counter').html('<b class="cur">'+(num+1)+'</b> of <b class="tot">'+vids.length+'</b>');
$('#next').html('<a href="#null" onclick="pick_vid('+(num+1)+')">NEXT SONG</a>');
$('#prev').html('<a href="#null" onclick="pick_vid('+(num-1)+')">PREV SONG</a>');

[COLOR="Red"]var x=function(){$('a[href*=randomize]').fadeIn('fast');}
$('a[href*=randomize]').fadeOut('normal',function(){setTimeout(x,3000);});
[/COLOR]
}
$(document).ready(function(){pick_vid();}); //autoplay random start
[/CODE]


like this ? this dont work too on my forum , it want start video or show iframe of embed
Copy linkTweet thisAlerts:
@PadonakApr 02.2012 — if you have
[CODE]<a href="#randomize" onclick="pick_vid()"><img src="http://i43.servimg.com/u/f43/11/33/28/68/button10.png" title="Random Song"></a>[/CODE]

in your markup this must work. anyway this page works good for me
[CODE]<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>123</title>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<style type="text/css">
body{text-align:center;font-family:Verdana,Arial;font-size:11px;background-color:#fff;color:#000;padding:0px;margin:30px;}
a:link,a:active,a:visited{color:#000;background-color:transparent;font-weight:bold;letter-spacing:1px;text-decoration:none;}
a:hover{color:Crimson;background-color:transparent;font-weight:bold;letter-spacing:1px;text-decoration:none;}
div{margin-top:5px;padding:20px;}
b{color:Crimson;}
.cur{color:Green;background-color:transparent;}
.tot{color:Darkorange;background-color:transparent;}
</style>
<script type="text/javascript">
var prefix="http://www.youtube.com/embed/",
suffix="?rel=0&am;autoplay=1",
vids=[
["aF4M0JtoIPk", "Reborn - Amina Khan"],
["KMxWhovYfzc", "New Muslims in Europe"],
["1eUOgD2Y9c8", "My Reversion To Islam"],
["hp0Wn8BoKyA", "Islam Saved My Life"]
];
function randomNumber(m,n){m=parseInt(m);n=parseInt(n);return Math.floor(Math.random()*(n-m+1))+m;}
function pick_vid(){
var num=(typeof(pick_vid.arguments[0])!='undefined')?pick_vid.arguments[0]:randomNumber(0,vids.length-1);
if(num==vids.length){num=0;}
$('#youtube_vid').attr('src',prefix+vids[num][0]+suffix);
$("#descr").html(vids[num][1]);
var ending='';
switch(num+1){
case 1:ending='st';break;
case 2:ending='nd';break;
case 3:ending='d';break;
default:ending='th';
}
$('#counter').html('<b class="cur">'+(num+1)+'-'+ending+'</b> of <b class="tot">'+vids.length+'</b> videos is being played now<br /><br /><a href="#null" onclick="pick_vid('+(num+1)+')">play next</a>');
var x=function(){$('a[href*=randomize]').fadeIn('fast');}
$('a[href*=randomize]').fadeOut('normal',function(){setTimeout(x,3000);});
}
$(document).ready(function(){pick_vid();});
</script>
</head>
<body>
<center>
<iframe id="youtube_vid" width="250" height="200" frameborder="0" allowfullscreen></iframe>
<div id="descr">song name goes here</div>
<div id="counter"></div>
<div><a href="#randomize" onclick="pick_vid()"><img src="http://i43.servimg.com/u/f43/11/33/28/68/button10.png" title="Random Song"></a></div>
</center>
</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@ludaludiauthorApr 02.2012 — it must be something, because forum ...
Copy linkTweet thisAlerts:
@ludaludiauthorApr 02.2012 — works, but i can't put like this
[CODE]<script type="text/javascript" src="http://example.forum.fm/18534.js"></script>[/CODE]
i need to put whole script together (jquery script + html)

its just whole script wont load when i put that 2 lines .... i don't understand
Copy linkTweet thisAlerts:
@ludaludiauthorApr 02.2012 — lol this works for me xD

<i>
</i>var x=function()
$('img[href*=randomize]').fadeIn('fast');
$('img[href*=randomize]').fadeOut('normal',function(){setTimeout(x,3000);});


i only tested on firefox .. work good ,but on new IE dont work ... but i don't care for ie ...
Copy linkTweet thisAlerts:
@PadonakApr 03.2012 — then try .hide() instead of fadeIn() - that damn IE has it's own synthax of opacity style that's why fadeIn() may not work good. but i've just tested my page in IE and the button disappears and appears again though without fading
Copy linkTweet thisAlerts:
@ludaludiauthorApr 03.2012 — [B]EDIT OMG this actually works on IE too[/B]

we have a winner !!! ?
$('a[href*=randomize]').hide();
$('a[href*=randomize]').delay(8000).fadeIn();


thx ... we finally finish this script ? its so cool ^^

now everything works fine (opera,chrome,firefox and finally on ie)
×

Success!

Help @ludaludi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...