PDA

View Full Version : Change iFrame Contents onclick


Bobba Buoy
11-20-2004, 06:20 AM
I am trying to get the contents of an iFrame to change its source when the user clicks a submit button. I was trying something like this:

onclick="this.form.infoFrame.src('../misc/blank.htm')"


Am I on the right track? This didn't work (primarily because I just pulled it out of my ....). How could I do this?

Thanks!

coothead
11-20-2004, 07:20 AM
Hi there Bobba Buoy,

do you mean like this...
<form action="#" onclick="document.getElementById('foo').src=document.forms[0][0].value; return false">
<div>
<input type="text" value="http://www.google.com"/>
<input type="submit" value="submit"/>
</div>
</form>

<iframe id="foo"></iframe>

Bobba Buoy
11-20-2004, 07:24 AM
Maybe. Explain the [0] [0] to me please?

Thanks for your time!

coothead
11-20-2004, 07:38 AM
Hi there Bobba Buoy,

document.forms[0][0] is a method of locating an element within a form.

By convention elements are numbered from 0.
In this case the first [0] refers to the first form and the second [0] refers to the first element within that form.

If you prefer you could just as easily use document.getElement ById like this...
<form action="#" onclick="document.getElementById('foo').src=document.getElementById('blah').value; return false">
<div>
<input id="blah" type="text" value="http://www.google.com"/>
<input type="submit" value="submit"/>
</div>
</form>

<iframe id="foo"></iframe>