Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change text in a parent frame...

Status
Not open for further replies.

prerob

Programmer
Apr 12, 2004
2
GB
Forgive me, I'm not great at JavaScript!

I need to convert this code below (which works fine in it's own page) to work across pages in a frameset. Essentially I need the text within the the Parent frame to be changed when a link in the child frame is clicked.

I'm having trouble converting this. Any help welcome!

<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
<!--
function changeCaption(textID, text) {
if(document.getElementById) {
document.getElementById(textID).innerHTML=text;
}
}
// -->
</script>
</head>
<body>

<a href="#" onclick="changeCaption('caption', 'text for image 1')" >...to this text when clicked.</a>

<span id="caption">This text changes...</span>

</body>
</html>
 
Code:
<html>
<head>
<title>Caption Changer</title>
<script type="text/javascript">
<!--
function changeCaption(textID, text) {
   if(frames[0].frames['beta']) {
      parent.getElementById(textID).innerHTML=text;
   }
}
// -->
</script>
</head>
<body>
<form name="alpha">
<a href="#" onclick="changeCaption('capa', 'text for image 1')" >...to this text when clicked.</a>
<iframe name="beta" width=100 height=100></iframe>
<span id="capa">This text changes...</span>
</form>
</body>
</html>

Not tested works only in IE I pressume...

Good Luck :)


__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 

My original <href="#" etc.> was causing the frameset to reload, so I changed it to this...

<a href="javascript:changeCaption('capa', 'text for image 1')" >...to this text when clicked.</a>

...but that doesn't do the trick. I now get an error of "frames.0.frames is null or not a number" in IE and "frames[0] has no properties" in FireFox.

:(
 
Code:
<html>
<head>
<title>Caption Changer</title>
<script type="text/javascript">
<!--
function changeCaption(text) {
document.getElementById("textID").innerHTML=text;}
// -->
</script>
</head>
<body>
<form name="alpha">
<iframe src="linkPage.htm" name="beta" width=100 height=100></iframe>
<hr size="1">
<div id="divBox" style="border:black 1px solid" style="width:100" style="height:100">
This text should change
</div>
</form>
</body>
</html>

alright this isnt the answer but it does show the same effect, just not from an iframe, that you will need to research more, I tried all the ways I know and I couldnt get it done, however this should serve as a workaround if need be, notice I cleaned up the script and added a src in the iframe, you need to utilize this src and paste the link syntax into it...

good luck

codeone

__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 
geez...I am waisting space like crazy today!!! Sorry...

heres the correct working code I left out the dang link syntax:

Code:
<html>
<head>
<title>Caption Changer</title>
<script type="text/javascript">
<!--
function changeCaption(text) {
document.getElementById("divBox").innerHTML=text;}
// -->
</script>
</head>
<body>
<form name="alpha">
<iframe src="linkPage.htm" name="beta" width=100 height=100></iframe>
<a href="Javascript:" onclick="changeCaption('Hello World!')" >Clik</a>
<hr size="1">
<div id="divBox" style="border:black 1px solid" style="width:100" style="height:100">
This text should change
</div>
</form>
</body>
</html>

__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top