The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> For loop in HTML, I don't know how to state a variable inside a loop
gabrielle
post Aug 26 2015, 11:00 AM
Post #1





Group: Members
Posts: 1
Joined: 26-August 15
Member No.: 23,448



Hey

I am quite new in HTTP and coding in general, and I am trying to implement this code:

<script>// <![CDATA[
var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player1;
var player2;
function onYouTubeIframeAPIReady() { player1 = new YT.Player('player1', { height: '169', width: '300', videoId: 'qnK81GsMdjE', playerVars:{autoplay:0,controls:0,showinfo:0},events: { 'onReady': stopVideo } }); player2 = new YT.Player('player2', { height: '169', width: '300', videoId: 'hP6DbEssRTE', playerVars:{autoplay:0,controls:0,showinfo:0},events: { 'onReady': stopVideo } }); } function onPlayerReady(event) { event.target.playVideo(); } function stopVideo() { player.stopVideo(); }
// ]]></script>
<div id="player1"></div>
<div id="player2"></div>

I would like to display many videos in the same page, and I know it would be better to use a for loop in order to write this code. I understand how a for loop works, but I don't know how to state the variables "player+i", for example, inside of this loop.

Any help will be appreciated, thanks!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Aug 26 2015, 01:43 PM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Where is your for loop code? Using your example of "player+i" and assuming the for loop counter is "i" then you would code it as "player"+i inside the loop.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 06:13 PM