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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a nodeValue as a image?

Status
Not open for further replies.

BenMiles

Technical User
Mar 11, 2008
12
US
I am trying to create a image gallery, pretty simple, just shows one image with a next and previous button. I got everything working I am not sure though how to make the nodeValue a image? Here is my xml:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<images>
    <pic>
        <image>thumbnails/thn1.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn2.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn3.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn4.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn5.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn6.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn7.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn8.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn9.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn10.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn11.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn12.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn13.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn14.jpg</image>
    </pic>
    <pic>
        <image>thumbnails/thn15.jpg</image>
    </pic>
</images>
and here is my html/javascript
Code:
<html>
<head>

<script type="text/javascript">
var xmlDoc;
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}

xmlDoc.async=false;
xmlDoc.load("images.xml");
var x=xmlDoc.getElementsByTagName("pic");
i=0;

function next()
{
if (i<x.length)
  {
  i++;
  display();
  }
}

function previous()
{

if (i>0)
  {
  i--;
  display();
  }
}

function display()
{
picture=(x[i].getElementsByTagName("image")[0].childNodes[0].nodeValue);

document.getElementById("show").innerHTML="<img src='picture'></img>";
}
</script>
</head>

<body onload="display()">
<div id='show'>
</div>
<br />
<input type="button" onclick="previous()" value="previous" />
<input type="button" onclick="next()" value="next" />

</body>
</html>
Thanks for the help!
 
If "picture" contains a URL to the image in question, then you're almost there:

Code:
document.getElementById('show').innerHTML = '<img src="' + picture + '" />';

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Sweet! it worked! why is there double "''" around picture?
 
One set of quotes is part of the HMTL that is actually being written to the page, while the other is the delimiter for the Javascript character string itself.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top