Click here to Skip to main content
11,923,517 members (66,400 online)
Rate this:
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 21:40pm
Edited 15-Mar-13 2:53am
sri senthil kumar 15-Mar-13 4:57am
can u post the code what you have written so far, so that we can help you?
Sweetynewb 15-Mar-13 7:47am
Please suggest me any solution..
sri senthil kumar 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 15-Mar-13 9:14am
Which url?
sri senthil kumar 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 16-Mar-13 1:15am

I just want to load new video on click of link..
sri senthil kumar 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151125.3 | 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