help using Javascript DOM to make link change in different frame

easyeman

Active member
Joined
Nov 16, 2005
Messages
28
Location
Decatur, AL
Programming Experience
1-3
I usually don't like frames but I have to use it for some reason in this assignment I'm doing.

I am trying to change a link on another frame (main.html) by a user clicking a button on another frame (header.html). I'm using DOM Javascript to do it, and I think I have how it should go except it's not working because I guess it is a different frame. How would I go about doing this and having it link? I'm stuck on what to do though it should be simple. Can anyone help me out?

Here's what I have for the script header:
HTML:
<script type="text/javascript">
        function changeLink()
        {
            document.getElementById('myAnchor').innerHTML="New Web Site"
            document.getElementById('myAnchor').href="http://www.newsite.com"
        }
    </script>
 
<input type="button" onclick="changeLink()" value="Change link to new site" />

This is on the main page which will be changed:
HTML:
<span style="font-size:11pt; color:red; font-family:Arial; font-weight:bold">Be sure
to visit <a id="myAnchor" href="http://www.nfpa.org" target="_blank">this official site.</a></span>
 
Try something like this:
VB.NET:
parent.frames[0].document.getElementById("myAnchor").innerHTML="New Web Site";
 
awesome, thanks that does help! I figured I just wasn't referencing the right thing. Since it's a frame I had to go a little further and add the parent to the start. What you posted didn't work at first but I just changed the element to parent.frames[1].document.getElementById('myAnchor') to reference the right one, but thanks for helping me figure it out! I'm a little new to this so trying to get the hang of everything. Thanks again
 
Back
Top