0

Please bear with me as I am still learning sharepoint and web technologies in general.

I have put a rotator on my sharepoint page using the easy to use script generated by http://usermanagedsolutions.com/SharePoint-User-Toolkit/Pages/Image-Rotator.aspx. I have the code below saved to a .txt file and I am linking to it in a CEWP. I am trying to add a caption under the image using the title field from picture library.

I thought I could just add table under the image and use getElementByID to replace the contents of the tag with variable that already has the title information in it, but my understanding must be off because it's not working. I am able to see the images, but the <td> remains empty.

I added in the table and this line document.getElementById("rotator_title").innerText=pAlt;hoping it would replace the <td> tag with value saved in pALT which I was hoping would be the item title. Here is my code. Any suggestions or am I way off?

<div class="IR-container">
<a>
    <img id="IR-img" border="0" height="153px" width="310px" src="/_layouts/images/blank.GIF"/>
    <span />
</a>
</div>
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr>
    <td id="rotator_title"></td>
</tr>
</table>

<script type="text/javascript">
/* Image Rotator - v 2.0 * Copyright (c) 2008-2010 Christophe Humbert *http://www.pathtosharepoint.com */
(function(){
var sec = 15;
var d = new Date();
var plURL ="/_vti_bin/owssvr.dll?Cmd=Display&XMLDATA=TRUE&List={xxxx-xxxx-xxx-}&View={xxx}&Source=xxxx="+d.getTime();
var IRi = document.getElementById("IR-img");
IRi.removeAttribute("id");
var i = -1;
function DisplayPicture(IRi,Items){i=Math.floor(Math.random()*Items.length);
var pURL ="/"+Items[i].getAttribute("ows_RequiredField");
pURL =pURL.replace(/\.([^\.]+)$/, "_$1") + ".jpg";
pURL =pURL.replace(/\/([^\/]+)$/,"/_w/"+"$1");
IRi.src =pURL;
var pAlt =Items[i].getAttribute("ows_NameOrTitle");
var pDesc ='';
IRi.alt =pAlt;
IRi.nextSibling.innerHTML=pDesc;
document.getElementById("rotator_title").innerText=pAlt;
}

try {var x=new XMLHttpRequest();}
catch(e){try{var x=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e){try{var x=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e){IR.innerHTML="Your browser does not support AJAX requests.";}}}x.onreadystatechange=function(){if (x.readyState==4){if (x.status==200){var xml=x.responseXML;
var Items= xml.getElementsByTagNameNS)?xml.getElementsByTagNameNS("*","row"):xml.getElementsByTagName("z\:row");
DisplayPicture(IRi,Items);
if (sec>0) {var Refresh=function(d,i,t){setInterval(function(){DisplayPicture(d,i);},t*1000);};Refresh(IRi,Items,sec);}}else{alert("Problem retrieving XML data");}}};x.open("GET",plURL,true);x.send(null);})();

</script>
1

There is a missing opening bracket in this line var Items= xml.getElementsByTagNameNS)?xml.getElementsByTagNameNS("*","row"):xml.getElementsByTagName("z\:row"); after getElementByTagNameNS which should be getElementByTagNameNS() which could be preventing the Items variable from being populated.

0

You might want to contact the author of the plugin for support on this - the way this code gets data out of SharePoint (by calling owssvr.dll) has been discouraged since 2007. The web services (Lists.asmx) were recommended in SharePoint 2007 and in 2010 we have the Javascript Client Side Object model, a far improved solution for getting data out of SharePoint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.