Click here to Skip to main content
11,804,574 members (76,278 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
Dear All,

There is page with one div in which i set video to play.
now i have one problem that, i want to change that video on click on video name.
I am using javascript to set video on click of name.

I am using ytplayer and playing youtube video.
but its not changing video.

Please help me....

My Javascript Code is :-
<script type="text/javascript">
       * Polling the player for information
      // Update a particular HTML element with a new value
      function updateHTML(elmId, value) {
        document.getElementById(elmId).innerHTML = value;
      // This function is called when an error is thrown by the player
      function onPlayerError(errorCode) {
        alert("An error occured of type:" + errorCode);
       // This function is called when the player changes state
      function onPlayerStateChange(newState) {
        updateHTML("playerState", newState);
function onYouTubePlayerReady(playerId,video_ID,wt_title,wt_synopsis,wt_div_id,user_id)
      //alert("hi" + wt_title);
                document.getElementById("lbl_title").innerHTML =wt_title;
                document.getElementById("lbl_synopsis").innerHTML =wt_synopsis;
                document.getElementById("hidden_wt_div_id").value =wt_div_id;
                document.getElementById("hidden_user_id").value =user_id;
                document.getElementById("hidden_video_id").value =video_ID;
                //alert("Video ID is=" + video_ID);

                ytplayer = document.getElementById("ytPlayer");
                setInterval(updatePlayerInfo, 250);
                ytplayer.addEventListener("onStateChange", "onPlayerStateChange");
                ytplayer.addEventListener("onError", "onPlayerError");
               //For Database entry
                var xmlhttp;
                if (window.XMLHttpRequest)      // code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp=new XMLHttpRequest();
                else if (window.ActiveXObject)      // code for IE6, IE5
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                    ert("Your browser does not support XMLHTTP!");
                xmlhttp.onreadystatechange = function()
                //end database
<pre lang="cs">function loadPlayer(videoID) {
        //var videoID =  document.getElementById(&quot;hidden_video_id&quot;).value.toString();
        //var videoID = &quot;gFnkHHQHVX0&quot;;

        alert(&quot;Function load player VideoID= &quot; + videoID);
        var params = { allowScriptAccess: &quot;always&quot; , allowfullscreen: &quot;true&quot; };
        var atts = { id: &quot;ytPlayer&quot; };
        var strSWF=&quot;; + videoID +&quot;?version=3&amp;enablejsapi=1&amp;playerapiid=player1&quot;;

        swfobject.embedSWF(&quot;; + videoID +
                           &quot;videoDiv&quot;, &quot;360&quot;, &quot;270&quot;, &quot;9&quot;, null, null, params, atts);
      function _run() {
Posted 14-Mar-13 20:40pm
Edited 15-Mar-13 1:53am
(no name)502.8K
sri senthil kumar at 15-Mar-13 4:57am
can u post the code what you have written so far, so that we can help you?
Sweetynewb at 15-Mar-13 7:47am
Please suggest me any solution..
sri senthil kumar at 15-Mar-13 8:22am
I havent used YTplayer. send me the url you got that. Will work on it and send you a solution ASAP.
Sweetynewb at 15-Mar-13 9:14am
Which url?
sri senthil kumar at 15-Mar-13 9:30am
I mean, just to get started. I want to check how the player code looks and i need to run it once :). After tht i can customize whatever the way you require.
Sweetynewb at 16-Mar-13 1:15am

I just want to load new video on click of link..
sri senthil kumar at 16-Mar-13 4:22am
check this code whether it works... is this what you want?


<div id="player">

<object width="640" height="360">
<param name="movie" value=""></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowScriptAccess" value="always"></param>
<embed src="" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="360"></embed>

HTY dargon
despicable me 2

function changevideo(id)

var divObj = document.getElementById('player');
divObj.innerHTML = '<object width="640" height="360">'+
'<param name="movie" value="'+ id + '?version=3"></param>' +
'<param name="allowFullScreen" value="true"></param>'+
'<param name="allowScriptAccess" value="always"></param>'+
'<embed src="'+id+'?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="360"></embed>'+

Sweetynewb at 16-Mar-13 6:15am
Thank you for try.. I solved that problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 3,205
1 Maciej Los 1,950
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100