Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple Instances of External Page - Ajax

Status
Not open for further replies.

berkshirea

Technical User
Mar 22, 2009
97
GB
Hi folks, I am experimenting on this Ajax Page Fetcher and it's been really nice.


I just would like to ask for your advice as to how would I be able to make it to work for multiple instances of SAME div id? I know I have to rename another div with a new id, but I just thought to ask you if there's a way to get around it? Because the external page won't load inside the other div.

Thanks for any inputs.


something like below.
Code:
<div id="joe"></div>
<script type="text/javascript">
// Fetch and display "content.htm" inside a DIV automatically as the page loads:
ajaxpagefetcher.load("joe", "content.htm", true)
</script>


<div id="joe"></div>
<script type="text/javascript">
// Fetch and display "content.htm" inside a DIV automatically as the page loads:
ajaxpagefetcher.load("joe", "content.htm", true)
</script>
 
ID's by definition must be unique. Since the ajax fetcher requires an ID one can assume it uses getElementByID which only ever returns one item. The first element it finds with the given ID. So it can only populate that.

You should never need to have repeat ID's for any reason as that defeats the purpose of the ID.

If you need to have more than one element with the same identifier, you should use the name attribute instead. You would of course probably need to modify the load() function to make use of the getElementsByName function instead, so you can have an array of elements that you can populate.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Not without seeing what you did, the link shows no usage of getElementsByName.

However as a note, getElementsByName returns an array of elements found with that name so you would need to loop through array to populate their innerHTML's with whatever it is the ajax loader produces.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top