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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Iframe, button link.

Status
Not open for further replies.

silentq

Programmer
Sep 17, 2007
16
CA
Hi,
I've made a simple Iframe which replaces one text with another. This all works the way I want it to with a link. I want it to do the same except with a button. This is what I have. (the link below the </html> works, but I want it to be a button.) The buton I have doesnt work right.

</head>

<body>
<script language="javascript">
function newWordLink() { window.location ="iframe2.php";
window.target="_iframe.php"; }
</script>

<p><form name="myform">
<input type="button" value="New Word" onclick="newWordLink()"</form></p>
<iframe name=_iframe src=iframe.php width=300 height=300 frameborder=0 scrolling=no> </iframe>

</body>

</html>

<a target="_iframe" href="iframe2.php">link</a>
 
If you copied and pasted the code above, you're missing a > from the button input statement.

If you didn't copy and paste from your original code, do that so we can see the real thing.

Lee
 
I've redone this a few times now, and the way somebody told me to do it was like this: enclose the initial text in a div tag, as well as the text in the iframe(which also needs to have an id. then I have to use this:

document.getElementById([matertext div id]).innerHTML=[iframename].document.getElementById('[iframe text div name]').innerHTML

That all sounds simple, but I dont have much experience with Javascript so I dont really know how to put it all together.
The last part would be to make a button with an onclick that performs the task. Help??
 
this is what I have now:
in a page 1:

<style type="text/css">
#div1 { color:red }
</style>

<div id="div1">
This is word one
</div>

in page 2:

<style type="text/css">
#div2 { color:blue }
</style>


<div id="div2">
This is word two
</div>

and now in the last page with the iframe:

<iframe name=_iframe src=iframe.php width=300 height=300 frameborder=0 scrolling=no> </iframe>

<script language="javascript">

function newtext() {
document.getElementById([div1]).innerHTML=[_iframe].document.getElementById('[div2]').innerHTML
}

</script>

<input type="button" value="New Text" onclick="newtext()" />


is this what he meant??
 
You'd probably profit from some of the online Javascript tutorials to learn what JS syntax is.

Try something like this (not tested, I rarely use frames).

Code:
document.getElementById([b][red]'[/red][/b]div1[b][red]'[/red][/b]).innerHTML=window.frames['_iframe'].document.getElementById([b][red]'[/red][/b]div2[b][red]'[/red][/b]).innerHTML;

Lee
 
Thanks. I've changed it all to be on one page now, which is a little less messy, but it doesnt work still.

<body>

<style type="text/css">
#div1 { color:red }
#div2 { color:blue }
</style>

<div id="div1">
This is word one
</div>



<iframe name=myiframe src=ipage3.php width=300 height=300 frameborder=0 scrolling=no><div id="div2">Hello</div></iframe>

<script language="javascript">

function newtext() {
document.getElementById('div1').innerHTML=myiframe.document.getElementById('div2').innerHTML;
}

</script>

<input type="button" value="New Text" onclick="newtext()" />

</body>

I changed the name of the iframe to "myiframe", because I dont think you can start with _. You can try it on your own server and see if it works...
 
I copied and pasted your code into a text editor, added form tags around the button, and it worked fine in IE 6 and Firefox.

What doesn't work? That claim is quite non-descriptive.

Lee
 
The actual function doesnt seems to work. I just did the same thing, I added the form tags and tried in FF and IE6. In both browsers I get a page that has "this is word one" at the top, a button in the middle, but clicking the button doesnt change the word.
 
I just tried it again, on a different computer from before with W2K and IE6, and it worked fine. I added the <form> tags around the button input and <html> tags around the whole page, but copied and pasted the latest code you posted above.

If you're using Firefox, do any errors show up in the error console?

Lee
 
No, but I just switched some things around, and now it works perfectly. I'm still not sure what the problem was, but thank you for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top