cyberdie Posted December 19, 2011 Share Posted December 19, 2011 Trying to create a variable, help please. wnat to be able to replace txt1 with the var youtube ID. <body><p><script>var txt1 = "h47fNaOb-JU";</script><object style="height: 390px; width: 640px"><param name="movie" value="https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist=h47fNaOb-JU,ma9I9VBKPiw&feature=player_embedded"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist=<script>txt1</script>,ma9I9VBKPiw&feature=player_embedded" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"></embed></var></object></p></body> Link to comment Share on other sites More sharing options...
niche Posted December 19, 2011 Share Posted December 19, 2011 You can't create variable with html, but you can set a value. Is that what you mean? Link to comment Share on other sites More sharing options...
ShadowMage Posted December 19, 2011 Share Posted December 19, 2011 I'm not sure if this will work, but you could try setting the src with JavaScript. Ie, var txt1 = "h47fNaOb-JU";document.getElementById("player").src = "https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist="+txt1+",ma9I9VBKPiw&feature=player_embedded"; ...and give the embed object an id:<embed id='player' src="" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"> Note: You'll need to make sure that the script is placed either in a onload handler or after the embed element or you'll get an undefined error saying that the element with id='player' doesn't exist. Link to comment Share on other sites More sharing options...
cyberdie Posted December 22, 2011 Author Share Posted December 22, 2011 I Did the changes as you suggested, although im not sure what is missing, I also supplied a function to allow for an onload event, as to my limited understanding anyway. <script type="text/javascript">function init(){var txt1 = "h47fNaOb-JU";document.getElementById("player").src = "[url="https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist="]https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist="+txt1+",ma9I9VBKPiw&feature=player_embedded[/url]";}window.onload=init;<object style="height: 390px; width: 640px"><param name="movie" value="[url="https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist=h47fNaOb-JU,ma9I9VBKPiw&feature=player_embedded"]https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist=h47fNaOb-JU,ma9I9VBKPiw&feature=player_embedded[/url]"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed id='player' src="[url="https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist="]https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist="+txt1+",ma9I9VBKPiw&feature=player_embedded[/url]" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"></object></script> Link to comment Share on other sites More sharing options...
thescientist Posted December 22, 2011 Share Posted December 22, 2011 Follow ShadowMages example for setting the src. His I'm not sure if this will work, but you could try setting the src with JavaScript. Ie, var txt1 = "h47fNaOb-JU";document.getElementById("player").src = "https://www.youtube.com/v/u1zgFlCw8Awversion=3&feature=player_embedded&autoplay=1&playlist="+txt1+",ma9I9VBKPiw&feature=player_embedded"; <embed id='player' src="" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"> Yours I Did the changes as you suggested, although im not sure what is missing, I also supplied a function to allow for an onload event, as to my limited understanding anyway.var txt1 = "h47fNaOb-JU";document.getElementById("player").src = "[url="https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist="]https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist="+txt1+",ma9I9VBKPiw&feature=player_embedded[/url]"; <embed id='player' src="[url="https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist="]https://www.youtube.com/v/u1zgFlCw8Aw?version=3&feature=player_embedded&autoplay=1&playlist="+txt1+",ma9I9VBKPiw&feature=player_embedded[/url]" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="425" height="344"> I don't know where are the extra source stuff is coming from unless they were put there from the forum. You should also be checking for errors in the console. also, all your HTML code for the object/embed is the javacript <script> tags. That's not where it belongs. You need to put in between the <body></body> tags somewhere on your page. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.