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!

Access to Iframe via Javascript when Iframe un-named.

Status
Not open for further replies.

tommytx

Programmer
Nov 27, 2002
28
US
How can I access an Iframe via javascript without the iframe having a name or Id. I understand they fall into the frames category and may be accessed with something like

<script>
alert(document.frames[0].n_one.value);
</script>

However I have tried various frames commands and no help.

Even the below don't work.

<a href="javascript:doit()";>Go do it</a>

<script>
function doit() {
alert(document.frames[0].forms[0]n_one.value);
}
</script>

This is an attempt to access an unnamed iframe and get the value located in n_one that is part of the iframed page.


Even tried the below with no help.

<a href="javascript:doit()" target="frames[0]";>Go do it</a>

<script>
function doit() {
alert(document.forms[0].n_one.value);
}
</script>

It works fine if I give the iframe a name like name=joeboy
then it works fine as below. Problem is the actual page has the iframe unnamed.

<a href="javascript:doit()" target="joeboy";>Go do it</a>

<script>
function doit() {
alert(document.forms[0].n_one.value);
}
</script>

Any advice will be greatly appreciated.

 
the frames object is a property of the window object, not document.

try
window.frames[0].document.forms[0].n_one.value


-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top