PDA

View Full Version : Ajax Dynamic Content - images



binchaud
01-31-2006, 11:14 PM
http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

Is it possible to call up images (gif,jpg) directly into the container div using this script? I've tried simply changing the request page like so
<a href="javascript:ajaxpage('a.gif', 'contentarea')"> and it gives an error of
GIF89a??

ddadmin
02-01-2006, 03:07 AM
You shouldn't use Ajax to dynamically call an image. Simply change the src property of an image to the one you wish to include. For example:


<img id="myimage" src="then.gif" />

<script type="text/javascript">
function changeimg(id, url){
document.getElementById(id).setAttribute("src", url)
}

changeimg("myimage", "http://google.com/logo.gif")
</script>

When changeimg() is run above, it changes the image from then.gif to logo.gif.