Microsoft Most Valuable Professional

Chris Pietschmann

An MVP From Wisconsin



JavaScript: How to get value from nested form in iframe?

Here is an example of how to get a value from a nested form in an iframe. It works in IE6, but not Netscape 7.1.

PageOne.htm
<html>
<head>
<script language='JavaScript'>

 function Search() {
  alert(document.frames("PageTwo").document.forms("Members").elements("Search").value);
 }

</script>
</head>
<body>
<input type='button' value='Search' onclick='Search();'>
<iframe name='PageTwo' src="PageTwo.htm" width='100%' height='100'>
</body>
</html>

PageTwo.htm
<html>
<body>
<form name='Members'>
    <input type='text' name='Search' value='Chris'>
</form>
</body>
</html>

Currently rated 3.6 by 5 people

  • Currently 3.6/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: General
Posted by crpietschmann on Thursday, August 12, 2004 11:12 PM
Permalink | Comments (6) | Post RSSRSS comment feed

Related posts

Comments

Koen

Wednesday, May 11, 2005 3:42 PM

Koen

Any idea how to do this in http://asp.net" target="_blank">ASP.NET ?

Harry

Wednesday, October 18, 2006 10:59 PM

Harry

document.frames is not a function. pfft.

Harry

Wednesday, October 18, 2006 11:17 PM

Harry

what it SHOULD be is:

window.frames['PageTwo'].document.forms['Members'].elements['Search'].value

Chris Pietschmann

Thursday, October 19, 2006 9:27 PM

Chris Pietschmann

My code above works perfectly in IE. You are correct in pointing out that document.frames is not a function in FireFox. So, if you want this to run fine in either web browswer, then you should use window.frames instead. Thanks for pointing that out!

Ersalan

Friday, October 20, 2006 11:41 AM

Ersalan

The code works brilliantly. Just wanted to add that the same code can be used to set values of a form inside an iframe. Thats what i realy needed and it worked flawlessly. Thanks

nreb10

Friday, November 03, 2006 7:56 AM

nreb10

i have problems in accessing some elements in an iframe.

my prob is i want to manipulate the color of the anchor (when active) in my iframe.

Can you help me how to do it?

this is my sample code:

window.frames['sample'].document.getElementById('test').focus()

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

Tuesday, January 06, 2009 8:56 PM

About the author

I'm Chris Pietschmann, go to the About Me page to learn more about me.

Search

Sponsors

Web.Maps.VE - ASP.NET AJAX Virtual Earth Mapping Server Control

Recent comments

Disclaimer


This work is licensed under a Creative Commons Attribution 3.0 United States License, unless explicitly stated otherwise within the posted content.
© Copyright 2004 - 2009 Chris Pietschmann