/    Sign up×
Community /Pin to ProfileBookmark

Form inside iframe

I have two pages. One with an iframe in the body:

<iframe name=ifr1 width=100 height=100 src=ifr1.html></iframe>

and ifr1.html with a form:

<form name=f1 id=f1>
<input type=”Hidden” name=”hid” value=”hid”>
</form>
In the main (first) file I want to access form f1 elements:
document.ifr1.document.f1 and
document.ifr1.document.forms[0] and
document.ifr1.document.forms[‘f1’] and
frames.ifr1.document.f1 gives me undefined.

How can I access form elements inside a iframe?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JHLJun 24.2003 — this work for me in ie5.5:

ifr1.document.f1.hid
Copy linkTweet thisAlerts:
@MMMikeauthorJun 24.2003 — I've tried that:

ifr1.document.f1.hid

For ifr1.document I get [object], but ifr1.document.f1 or ifr1.document.forms[0] gives [b]undefined[/b] too, as if there were no forms. Just can't get it...

Browser is IE 6.0
Copy linkTweet thisAlerts:
@JHLJun 24.2003 — i've tired

alert(ifr1.document.f1);

and it give me [object].

Sorry, can't seems to solve your problem. Maybe some other people here can.
Copy linkTweet thisAlerts:
@MMMikeauthorJun 24.2003 — Thanks to JHL. Maybe I've missed something else in my code files. Are there any requirements?
Copy linkTweet thisAlerts:
@JHLJun 25.2003 — this is the code i used:

test1.html

<html>

<head>

<script type='text/javascript'>

function testing()

{

alert(ifr1.document.f1);

}

</script>

</head>

<body>

<iframe name="ifr1" width=100 height=100 src='test2.html'></iframe>

<input type="button" value="test" onclick="testing()">

</body>

</html>


test2.html

<html>

<head>

</head>

<body>

<form name=f1 id=f1>

<input type="Hidden" name="hid" value="hid">

</form>

</body>

</html>
×

Success!

Help @MMMike spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...