How to display the current title from a json request

Go To StackoverFlow.com

0

I'm looking to get a title of the specific item that is being selected on my page:

function response(jsonData) {
    var items = jsonData["items"];
    var tDiv = document.getElementById("dynamicVideos");
    var uDiv = document.getElementById("videoInfo");
    var i=0;        

    while (i<items.length) {        

        var str = "";
        str += '<div class="tvVideo">';
        str += '<div class="thumb" onClick="playTitleFromList(' + items[i].id + ')"><img src="' + items[i].thumbnailURL + '"/></div>';
        str += '<p class="vidTitle">' + items[i].name + ' (' + formatTime(items[i].length) + ')'+ '</p>';
        str += '<p class="vidDescription">' + items[i].shortDescription + '</p>';
        str += '</div>';

        tDiv.innerHTML += str;

        i++;
    }

    var str2 = "";
    str2 += '<div class="videoTitle">';
    str2 += '<h3 id="videoTitle">' + items[0].name + '</h3>';
    str2 += '</div><!-- Video Title -->';
    str2 += '<div class="videoDescription">';
    str2 += '<p id="videoDescription">' + items[0].longDescription + '</p>';
    str2 += '</div><!-- Video Description -->';
    str2 += '<div class="divide"></div>';
    str2 += '<div id="videoDonate"></div>';
    str2 += '<div id="videoTAF"></div>';
    str2 += '<div id="videoTime"></div>';

    uDiv.innerHTML += str2;
}

The bottom portion of the code should display the video selected's info as the top code block returns the list of video.

2012-04-03 20:27
by TikaL13
What is "selected video"? Is that something that is returned in the JSON - amit_g 2012-04-03 20:32


1

If by "selected" you mean the last item you've clicked, you'll need to add code to playTitleFromList to populate your page with the data. That function will need access to the same data that's in jsonData so it has the values it needs. That function is currently passed the ID that needs to be looked up; alternately, you could change the code so that i is passed as the parameter rather than the id so that you can just access the item in the array.

2012-04-03 20:33
by Jacob
So are you saying that this function playTitleFromList needs to be outside of function response - TikaL13 2012-04-03 20:53
Since you're referencing it as part of an onclick attribute, it will need to be available in the global scope. Otherwise, you'll need to attach the click handler differently - Jacob 2012-04-03 21:16
Ads