/    Sign up×
Community /Pin to ProfileBookmark

Problem accessing form in first frame

I have the following frameset:

[code=html]<html>

<head>
</head>

<frameset cols=”50%,*”>
<frame name=”frame1″ src=”frame1.htm”>
<frame name=”frame2″ src=”frame2.htm”>
</frameset>

</html>[/code]

The frame1.htm page looks like this:

[code=html]<html>

<head>
</head>

<body>

<h4>Frame 1</h4>

<form name=”form1″>

<input type=”text” name=”text1″ value=”value1″ />

</form>

<script language=”JavaScript” type=”text/javascript”>

var txtBoxValue2=window.parent.frame2.document.form2.text2.value;

document.write(“The value in the text box in Frame 2 is: “+txtBoxValue2);

</script>

</body>

</html>[/code]

frame2.htm looks like this:

[code=html]<html>

<head>
</head>

<body>

<h4>Frame 2</h4>

<form name=”form2″>

<input type=”text” name=”text2″ value=”value2″/>

</form>

<script language=”JavaScript” type=”text/javascript”>

var txtBoxValue1=window.parent.frame1.document.form1.text1.value;

document.write(“The value in the text box in Frame 1 is: “+txtBoxValue1);

</script>

</body>

</html>[/code]

Why is it that this code only works to access the value in form 1, frame 1 [I]from [/I]frame 2, and the output is blank when trying to access form 2 in frame 2 [I]from [/I]frame 1?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @CollegeWebbie 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.17,
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,
)...