View Full Version : help with javascript please!

12-09-2004, 03:51 PM
I have a main page (main.php) and the are 2 iframes in it. The menu is located in main.php and what I want to happen is that the 2 iframes will change its contents when a link in the menu is clicked. Is there a way for me to do this?

I tried this code

function loadIframe(iframeName, url) {

frames[iframeName].location.href = url;


but I can't make it work when I place it in my link tag like this

<a href="#" onClick="javascript:loadIframe('mIframe','lesson.php')">google</a>

WHat's wrong with what I'm doing? Please somebody help me 'xoz I'm stuck! :eek:

12-10-2004, 03:01 PM

you don't need JS to do that.

<a href="lesson.php" target="mIframe">google</a>

will do the job just fine.


12-12-2004, 03:19 AM
hereīs one thing:

instead of:
<a href="#" onClick="javascript:loadIframe('mIframe','lesson.php')">google</a>
put the onclick content on the href:
<a href="javascript:loadIframe('mIframe','lesson.php')">google</a>
if you want to use "onclick" to call a function just do this:
<a href="#" onClick="loadIframe('mIframe','lesson.php');return false;">google</a>
dont add the "javascript:" thing

another thing, Im not sure but I though you could call an <iframe> by writing down this: "document.iframename.location.href" you dont need to have the "frames.iframe..." unless you confused <iframe>īs with <frameset>īs...

hope that helped