File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Accessing iframe elements in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Accessing iframe elements in javascript" Watch "Accessing iframe elements in javascript" New topic

Accessing iframe elements in javascript

Manohar Saddala

Joined: Jul 11, 2007
Posts: 12
Hi All,

I have an html page which consists of iframe. In the iframe i had defined a form with two input elements and one button element.when i click the button in will be calling a javascript.

what my problem is in the javascript i am unable to get the input elements values defined in the form and i am unable to perform the form related functions like form.action(), form.submit().. etc..

Please help me regarding the issue..


Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Talk to the iframe from the parent:
document.getElementById("iframeId").formName.elementName.value = "foo";

Talk to the parent from the iframe
parent.formName.elementName.value = "bar";

Manohar Saddala

Joined: Jul 11, 2007
Posts: 12

i had tried the way you had said but iam getting the error like is null or not an object.

my page was designed like below:

in the body tag
i have an button which calls a javascript funtion
i have a iframe which has a form as a member to the iframe.I the form i had an text box.

what i want to do is when i click on the button in the javascript i need to validate the value in the textbox and then i want to submit the form to server side.

It is sorta covered in the JavaRanch Style Guide.
subject: Accessing iframe elements in javascript
It's not a secret anymore!