/    Sign up×
Community /Pin to ProfileBookmark

Accessing another iFrame from an iFrame

Ok, I’m stuck, been googling for two days without figuring this out, fairly new to javascript too! so be gentle.

I have a page with two iFrames on it name and id set to iframe1 and iframe2
On iframe2 I have javascript function that I want to add some text to a textarea on iframe1, the function is running, but nothing is happening, the textarea is called ‘what’ and form is called ‘myform’. Heres what I’ve tried so far…

[CODE]
top.document.getElementById(‘iframe1’).getElementById(‘what’).value=’xxxxx’;
window.frames[‘iframe1’].document.getElementById(‘what’).value=”xyxyxyx”;
top.document.getElementById(‘iframe1’).document.forms[‘myform’].elements[‘what’].value=’Arrrggghh!’;
window.frames[0].document.forms[‘myform’].elements[‘what’].value=’why isnt this working!’;

(also tried [1] just in case)

[/CODE]

Done variations on the above, but nothing appears, I used a firefox plugin to debug the javascript, and can confirm it is running the line.
Both iframes and the main page are all on the same domain, same web server, same folder.

GrumpyMode=True;

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 22.2009 — <i>
</i>parent.document.getElementById('iframe1').contentWindow.document.getElementById('what').value="xyxyxyx";
Copy linkTweet thisAlerts:
@satscapeauthorJul 22.2009 — Thank you Kor, works a treat.
×

Success!

Help @satscape 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 6.18,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...