PDA

View Full Version : Dynamic Ajax Content with div class instead of id



inflicted
08-17-2006, 11:15 PM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem: Is it possible to alter the script so it points to a div class instead of an id?

thanks

jscheuer1
08-18-2006, 08:13 AM
I'm not sure why you would want to do this. Are you trying to fill multiple divisions on the same page with the same content simultaneously? Or, is it that you just prefer class to id? Either way, you could change this:


function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

to:


function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
var theDivs=document.getElementsByTagName('div');
for (var i_tem = 0; i_tem < theDivs.length; i_tem++)
if (theDivs[i_tem].className==containerid)
theDivs[i_tem].innerHTML=page_request.responseText
}
}

Now class will work like id used to for this script (id will no longer work). I wrote the above for divisions only but, it could be written for other elements or, for all elements that support the class attribute.

inflicted
08-18-2006, 12:14 PM
Thanks a lot John!

I do want to fill multiple divisions, as I want to use it to show entries of my CMS(Expression Engine).
Otherwise it would fill the page with div id's, and that is not what id's stand for, do they. ;)

I had already found a workaround by setting the entry limit to "1", but this is even better!

thanks again...