By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

How to get FORM values from an IFRAME ?

P: n/a
Pb with javascript.
I've a 'main.html' script containing an 'iframe.html' IFRAME.
The 'iframe.html' is containing a form.
My problem is that i'm unable to get form fields values. What's the
syntax ???

NB: the script has to be generic, because it has to work with any .html
(i may don't know form's name and iframe's name).

Thanks
=== MAIN.HTML ===

<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
<title>main</title>
</head>
<body>

<iframe name="pub" width="200" height="100" src="iframe.html">
</iframe>
<script language="Javascript">

// HERE'S MY PROBLEM: IT DISPLAYS ANYTHING !!!
document.write(document.frames[0].document.forms[0].elements[0].value);

</script>

</body>
</html>
=== IFRAME.HTML ===

<html>

<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080"
alink="#ff0000">

<form method="POST" action="x" name="formIFrame">
<input type="text" name="name2" value="value2">
<input type="submit" value="POST2">
</form>

</body>
</html>

Oct 2 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a


Ding dong!, frames[] collection is at the window level, not document,
including iframes, so, window.frames[0].

Danny
Oct 3 '05 #2

P: n/a
Sorry Danny, but i still got the problem

(...)
// HERE'S MY PROBLEM: IT DISPLAYS ANYTHING !!!
document.write(window.frames[0].document.forms[0].elements[0].value);
(...)

Djdave

Oct 3 '05 #3

P: n/a
djdave said the following on 10/3/2005 2:59 AM:
Sorry Danny, but i still got the problem
Ignore Danny, he seems to think that replying to nothing is the way to
post here, it's not. Please quote what you are replying to, this is
Usenet, not Email.
(...)
// HERE'S MY PROBLEM: IT DISPLAYS ANYTHING !!!
document.write(window.frames[0].document.forms[0].elements[0].value);


It won't be available until after the element in the form in the
document in the frame is loaded. In your sample code, it is trying to
access something that hasn't been loaded yet. Try changing it to the
onload event and alert it and see what you get.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 3 '05 #4

P: n/a
Danny,

It works well when i've a form without iframe.

So, why it shouldn't when a form is insite a iframe ?

Furthermore, i need it works before the form is submitted.

Thanks.

Oct 3 '05 #5

P: n/a
Danny,
It works well when i've a form without iframe.
So, why it shouldn't when a form is inside a iframe ?
Furthermore, i need it works before the form is submitted.
Thanks.

Oct 3 '05 #6

P: n/a
djdave said the following on 10/3/2005 11:19 AM:
Danny,
This is Usenet, not Email.

Please quote what you are replying to.

It works well when i've a form without iframe.
So, why it shouldn't when a form is inside a iframe ?


Because your referencing is incorrect.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer: Not quoting at all.
Question: Whats worse than top-posting?
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Oct 3 '05 #7

P: n/a
Ok, but could you please tell me the referencing i've to use ?

(i'm javascript's beginner and my english isn't very good !!!)

Thanks for your help.

Oct 3 '05 #8

P: n/a
djdave said the following on 10/3/2005 12:47 PM:
Ok, but could you please tell me the referencing i've to use ?
You begin by quoting what you are replying to.

If you want to post a followup via groups.google.com, don't use
the "Reply" link at the bottom of the article. Click on "show
options" at the top of the article, then click on the "Reply" at
the bottom of the article headers.
(i'm javascript's beginner and my english isn't very good !!!)


Nothing wrong with not being good in English.

Show a sample URL of a sample page that you can't get to work.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 3 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.