How to get FORM values from an IFRAME ?

D

djdave

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>
 
D

djdave

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
 
R

Randy Webb

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.
 
D

djdave

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.
 
D

djdave

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.
 
R

Randy Webb

djdave said the following on 10/3/2005 11:19 AM:

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?
 
D

djdave

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.
 
R

Randy Webb

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top