PDA

View Full Version : Change img & page title with onclick


burger
05-02-2003, 03:57 AM
Hi,
I'm using frames in my pages, a menu and content frame. In the menu frame I want to change an image and the title of the page with the same link. I can make each event change using onclick but different links, is there a way to make the 2 events change with one link using onclick?

Thanks

The script below:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function changeTitle(newTitle) {
top.document.title=newTitle;
}
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<p><img name="aog" src="image1.jpg" width="100" height="100"></p>

<p><a href="content.htm" onclick='aog.src="image1.jpg"' target="mainFrame">Page One</a></p>
<p><a href="content2.htm" onclick='aog.src="image2.jpg"' target="mainFrame">Page Two</a></p>

<p><a href="content.htm" onclick="changeTitle('Page One');" target="mainFrame">Page One</a></p>
<p><a href="content2.htm" onclick="changeTitle('Page Two');" target="mainFrame">Page Two</a></p>

</body>
</html>

smeagol
05-02-2003, 04:03 AM
Just put both events in the same event handler. Like this:

<p><a href="content.htm" onclick="aog.src='image1.jpg'; changeTitle('Page One');" target="mainFrame">Page One</a></p>
<p><a href="content2.htm" onclick="aog.src='image2.jpg'; changeTitle('Page Two);" target="mainFrame">Page Two</a></p>

You just separate the events with a semicolon.

burger
05-02-2003, 04:19 AM
thanks heaps, didn't work at first but then I had another look at the code and noticed a missing ' !! All is good now :)