faqts : Computers : Programming : Languages : JavaScript : Document

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 8 people (88%) answered Yes
Recently 7 of 8 people (88%) answered Yes

Entry

If I have a frameset with 2 frames f1 and f2, how can I access an element in form f1 from form f2?

Jul 30th, 2001 23:36
Joe Lipman, Balaji B R,


Have you tried assigning names to the forms within?
eg.
<FRAMESET COLS="50%,*" BORDER=no FRAMEBORDER=0 FRAMESPACING=0>
	<FRAME SRC="form1.htm" NAME="f1">
	<FRAME SRC="form2.htm" NAME="f2">
</FRAMESET>
where form1.htm contains in the body
<FORM NAME="fromFrom">
       <INPUT NAME="fromElement" VALUE="I'm a lumberjack and I'm okay">
</FORM>
and form2.htm
<FORM NAME="toForm">
       <INPUT NAME="toElement" VALUE="">
       <INPUT TYPE="button" NAME="getIt" VALUE="Get It" 
ONCLICK="retrieve()">
</FORM>
and the header would contain the script
<SCRIPT NAME="JavaScript">
<!--
       function retrieve() {
                IfoundIt=parent.f1.document.fromFrom.fromElement.value;
                parent.f2.document.toForm.toElement.value=IfoundIt;
                // IfoundIt variable because this text wraps
                // if in f2 you can remove parent.f2.
       }
//-->
</SCRIPT>
The above script is set to be accommodated in either frame
however if the script is in f1 (form1.htm) and the function
is called from f2 (form2.htm), the code should be changed to
	ONCLICK="parent.f1.retrieve()"