How can I access form fields in iframe through Javascript when clicking an event outside iframe?

How can I access form fields in iframe through Javascript when clicking an event outside iframe?

On a Web page I am displaying a form using iframe. On clicking one event (outside the iframe), I want to access the form fields (in iframe) through Javascript. Would you please suggest how to do that? Thanks in advance.

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

To set yourName to the value of the field "yourname" of the myForm form in the iframe, try this.
var iframe = document.getElementById
("myFrame");
var iframeDoc = iframe.Document;   
var iframeForm = iframeDoc.
getElementById("myForm");
var yourName = iframeForm.
yourname.value;

Do you have comments on this Ask the Expert Q&A? Let us know.

Dig Deeper

This was first published in February 2004