NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Javascript Assistance

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 12-06-2010, 11:36 AM THREAD STARTER               #1 (permalink)
New Member
Join Date: Dec 2010
Posts: 11
Ethrock is an unknown quantity at this point
 



Javascript Assistance


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;


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!)
????: NamePros.com http://www.namepros.com/programming/690509-javascript-assistance.html

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!
Ethrock is offline   Reply With Quote
Old 12-06-2010, 03:37 PM   #2 (permalink)
NamePros Regular
 
hollywood's Avatar
Join Date: Jan 2007
Location: Namepros
Posts: 240
hollywood is a jewel in the roughhollywood is a jewel in the roughhollywood is a jewel in the rough
 



I would be very interested to know where you found this source code.

In this case you need to add the 'movietext' id where you want the video to display, so getElementById can find it. something like this will work:
Code:
<div id="movietext"></div>
__________________
"Because it really is that simple imho. If you don't want sheep for users, don't treat your users like sheep."
Memory Chips | Euro ETF | Flowers | A1c Levels & Diabetes
hollywood is offline   Reply With Quote
Old 12-06-2010, 07:51 PM THREAD STARTER               #3 (permalink)
New Member
Join Date: Dec 2010
Posts: 11
Ethrock is an unknown quantity at this point
 



So would that go after the <script> or outside of the bounds of the script? Ie would it be <div><script>info</script></div> or <script><div>info</div></script>

?
Ethrock is offline   Reply With Quote
Old 12-06-2010, 09:35 PM   #4 (permalink)
NamePros Regular
 
hollywood's Avatar
Join Date: Jan 2007
Location: Namepros
Posts: 240
hollywood is a jewel in the roughhollywood is a jewel in the roughhollywood is a jewel in the rough
 



so here I spend the time to help you and you won't answer my simple question?

?
__________________
"Because it really is that simple imho. If you don't want sheep for users, don't treat your users like sheep."
Memory Chips | Euro ETF | Flowers | A1c Levels & Diabetes
hollywood is offline   Reply With Quote
Old 12-07-2010, 11:13 AM   #5 (permalink)
NamePros Member
Join Date: Dec 2008
Posts: 59
superiordomainnames will become famous soon enoughsuperiordomainnames will become famous soon enough
 



Originally Posted by hollywood View Post
so here I spend the time to help you and you won't answer my simple question?
????: NamePros.com http://www.namepros.com/showthread.php?t=690509

?
lol, you know I actually tried the code, but it didn't work. I didn't look into why even if he had the element with the proper id.
superiordomainnames is offline   Reply With Quote
Old 12-07-2010, 06:29 PM THREAD STARTER               #6 (permalink)
New Member
Join Date: Dec 2010
Posts: 11
Ethrock is an unknown quantity at this point
 



Originally Posted by superiordomainnames View Post
lol, you know I actually tried the code, but it didn't work. I didn't look into why even if he had the element with the proper id.
Is there any insight you could offer as to why this might be?
????: NamePros.com http://www.namepros.com/showthread.php?t=690509

Originally Posted by hollywood View Post
so here I spend the time to help you and you won't answer my simple question?

?
My apologies. I gathered the code from a forum post which can be located here: http://forums.aspfree.com/html-javas...eo-200545.html

there is html code to embed it provided in this topic but I found that the iframe method was unsuccessful.
Ethrock is offline   Reply With Quote
Old 12-08-2010, 12:58 AM   #7 (permalink)
NamePros Regular
 
hollywood's Avatar
Join Date: Jan 2007
Location: Namepros
Posts: 240
hollywood is a jewel in the roughhollywood is a jewel in the roughhollywood is a jewel in the rough
 



ok thanks for the response, appreciated
????: NamePros.com http://www.namepros.com/showthread.php?t=690509

here's what I would do:

up in the <head> portion of your HTML page, put the call that loads the .js file remotely.

Then, down in the body of your page, call the function with javascript.

That function uses a standard technique of writing its output to a particular ID that is specified in the CSS. Wherever you choose to place the <div id="movietext"></div>
on your HTML page, that is the spot where the js function is going to write the embed code that shows the video.
__________________
"Because it really is that simple imho. If you don't want sheep for users, don't treat your users like sheep."
Memory Chips | Euro ETF | Flowers | A1c Levels & Diabetes
hollywood is offline   Reply With Quote
Old 12-09-2010, 06:14 PM THREAD STARTER               #8 (permalink)
New Member
Join Date: Dec 2010
Posts: 11
Ethrock is an unknown quantity at this point
 



Originally Posted by hollywood View Post
ok thanks for the response, appreciated
????: NamePros.com http://www.namepros.com/showthread.php?t=690509

here's what I would do:

up in the <head> portion of your HTML page, put the call that loads the .js file remotely.

Then, down in the body of your page, call the function with javascript.

That function uses a standard technique of writing its output to a particular ID that is specified in the CSS. Wherever you choose to place the <div id="movietext"></div>
on your HTML page, that is the spot where the js function is going to write the embed code that shows the video.

This also was not successful which leads me to believe the javascript is the problem... Anybody know what might be wrong with it?
Ethrock is offline   Reply With Quote
Old 12-09-2010, 07:07 PM   #9 (permalink)
Qc4
NamePros Member
Join Date: Mar 2010
Posts: 124
Qc4 is on a distinguished road
 



Above, you have the randomVideo() call inside the <script> tag, which won't work. You need to make sure it's called after the movietext div is rendered in your browser, so try putting it either in the body after the movietext div or in an onload event.
__________________
DirectWWW - an OpenSRS reseller
Qc4 is offline   Reply With Quote
Old 12-09-2010, 07:10 PM   #10 (permalink)
NamePros Regular
 
baxter's Avatar
Join Date: Apr 2006
Posts: 360
baxter is just really nicebaxter is just really nicebaxter is just really nicebaxter is just really nice
 


Ethan Allen Fund Save The Children
I just ran the code you had and it worked almost perfect for me, you have to make sure you have the following:

Code:
<div id="movietext"></div>
Then you can run randomVideo() after the page has fully loaded. There was one typo in the code, document.write(mainlink) isn't really needed since you putting it into the div element with the innerHTML call. Heres the adjusted code:
????: NamePros.com http://www.namepros.com/showthread.php?t=690509

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;

return false;
}
now tests on my localhost, it took almost 5-10 seconds for the video to load after running the randomVideo call so make sure you give it time to load the video.

Cheers,

Jay
__________________
Canadian Domain Registrar Ready.ca
baxter is offline   Reply With Quote
Old 12-09-2010, 09:57 PM THREAD STARTER               #11 (permalink)
New Member
Join Date: Dec 2010
Posts: 11
Ethrock is an unknown quantity at this point
 



Thank you infinitely to everyones support! Thank you guys! I learned lots toying with this. Got it to work, I'm so happy <3
Ethrock is offline   Reply With Quote
Old 12-10-2010, 05:40 PM THREAD STARTER               #12 (permalink)
New Member
Join Date: Dec 2010
Posts: 11
Ethrock is an unknown quantity at this point
 



Originally Posted by Ethrock View Post
Thank you infinitely to everyones support! Thank you guys! I learned lots toying with this. Got it to work, I'm so happy <3
It would actually appear I still need some help, I want to have mutliple of these items appear on a single page, but adding additional randomVideo(); commands, adding new <script> tags, and adding new <div> tags do not work. It will only let me have one (or any multiples display the same video) I want all of them to draw from the same array. What should I do?
Ethrock is offline   Reply With Quote
Old 12-10-2010, 07:28 PM   #13 (permalink)
Qc4
NamePros Member
Join Date: Mar 2010
Posts: 124
Qc4 is on a distinguished road
 



One possibility would be to change:

Code:
function randomVideo(){
to:

Code:
function randomVideo(id){
and change:

Code:
document.getElementById('movietext').innerHTML = mainlink;
to:

Code:
document.getElementById(id).innerHTML = mainlink;
Now, you can create as many <div>s as you want. Just be sure to call the randomVideo() function for each:

Code:
<div id="movietext1"></div>
<div id="movietext2"></div>
<div id="movietext3"></div>

<script type="text/javascript">
randomVideo('movietext1');
randomVideo('movietext2');
randomVideo('movietext3');
</script>
__________________
DirectWWW - an OpenSRS reseller
Qc4 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Small Javascript Project Rudy Web Development Wanted 1 09-07-2008 10:07 AM
JSeditor.com (JavaScript editor) edder Domains For Sale - Fixed Price 0 12-12-2007 09:42 PM
Wanted: Javascript expert cvxdes Web Development Wanted 0 03-25-2006 06:37 AM
Adding Javascript to pre-existing Javascript Page nigelwong Programming 0 12-16-2005 06:20 AM

 
All times are GMT -7. The time now is 02:42 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger