Jump to content
cyberdie

Creating A Var In Html   

Recommended Posts

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>

Edited by cyberdie

Share this post


Link to post
Share on other sites

You can't create variable with html, but you can set a value. Is that what you mean?

Share this post


Link to post
Share on other sites

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.

Edited by ShadowMage

Share this post


Link to post
Share on other sites

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>

Share this post


Link to post
Share on other sites

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. Edited by thescientist

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...