adamWeiler
01-26-2008, 01:54 PM
Hi, I'm not too sure how to do something with Javascript. I am making a Photogallery from textbook instructions. The gallery itself works; the user clicks on a link and the image appears on the same page. Clicking another link loads another picture in the same spot, on the same page. This is the code:
HTML: <a onclick="return showPic(this,1)" href="images/photographs/image1.jpeg">Image One</a>
<a onclick="return showPic(this,2)" href="images/photographs/image2.jpeg">Image Two</a>
Javascript:
function showPic (whichpic, numeral) {
//Determines which picture to display.
if (document.getElementById) {
document.getElementById('placeholder').src = whichpic.href;
if (whichpic.title) {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
} else {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
}
return false;
} else {
return true;
}
}
My problem is, nothing happens until the user clicks on one of the links. I want to use body onload so an image loads when the page opens up. I'm not sure how to do this, because the link uses this, and I don't fully understand how to apply a this to a body onLoad.
Any suggestions on how to do this?
HTML: <a onclick="return showPic(this,1)" href="images/photographs/image1.jpeg">Image One</a>
<a onclick="return showPic(this,2)" href="images/photographs/image2.jpeg">Image Two</a>
Javascript:
function showPic (whichpic, numeral) {
//Determines which picture to display.
if (document.getElementById) {
document.getElementById('placeholder').src = whichpic.href;
if (whichpic.title) {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
} else {
document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
}
return false;
} else {
return true;
}
}
My problem is, nothing happens until the user clicks on one of the links. I want to use body onload so an image loads when the page opens up. I'm not sure how to do this, because the link uses this, and I don't fully understand how to apply a this to a body onLoad.
Any suggestions on how to do this?