I'm on the first chapter of a book "head first ajax" and I wrote the exact code the book says and it just won't work!
there are 4 thumbnails pics on my page (in div id=thumbnailPane) and when u click on 1 of the pics there should be displayed a bigger picture in a div (id=detailsPane) that is initially empty.
but when I click on any of the thumbnails nothing happens!
here's the code-
html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Rob's Rock 'n' Roll Memorabilia</title>
<link rel="stylesheet" href="css/default.css" />
<script src="thumbnails.js" type="text/javascript"></script>
</head>
<body>
<div id="wrapper">
<img src="images/logotypeLeft.png" alt="Rob's Rock 'n' Roll Memorabilia"
width="394" height="91" id="logotypeLeft" />
<img src="images/logotypeRight.png" alt="Rob's Rock 'n' Roll Memorabilia"
width="415" height="92" id="logotypeRight" />
<div id="introPane">
<p>Are you looking for the perfect gift for the rock fan in your life?
Maybe you want a guitar with some history behind it, or a conversation
piece for your next big shindig. Look no further! Here you'll find all
sorts of great memorabilia from the golden age of rock and roll.</p>
<p><strong>Click on an image to the left for more details.</strong></p>
</div>
<div id="thumbnailPane">
<img src="images/itemGuitar.jpg" width="301" height="105" alt="guitar"
title="itemGuitar" id="itemGuitar" />
<img src="images/itemShades.jpg" alt="sunglasses" width="301" height="88"
title="itemShades" id="itemShades" />
<img src="images/itemCowbell.jpg" alt="cowbell" width="301" height="126"
title="itemCowbell" id="itemCowbell" />
<img src="images/itemHat.jpg" alt="hat" width="300" height="152"
title="itemHat" id="itemHat" />
</div>
<div id="detailsPane">
<img src="images/blank-detail.jpg" width="346" height="153" id="itemDetail" />
<div id="description"></div>
</div>
</div>
</body>
</html>
the thumbnails.js code:
window.onload=initPage;
function initPage(){
alert("yes1");
thumbs=document.getElementById("thumbnailPane").getElementByTagName("img");
alert("yes2");
for(var i=0;i<thumbs.length; i++) {
alert(i);
image=thumbs[i];
image.onclick=function(){
detailURL='images/'+ this.title+'-detail.jpg';
document.getElementById("itemDetail").src=detailURL;
getDetails(this.title);
}
}
}
alert 'yes1' is popping out when I refresh the page but alert 'yes2' doesn't.