faqts : Computers : Programming : Languages : JavaScript

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

49 of 65 people (75%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Can you read a javascript variable(DOM object) from another frame within a same frameset?

Apr 5th, 2008 20:21
ha mo, Darton Williams, Jiga What,


Just name the frames like so:
<FRAMESET rows="100,*">
<FRAME src="test2.html" name="topFrame">
<FRAME src="test3.html" name="bottomFrame">
</FRAMESET>
and you'll be able to access anything (including constants) between 
frames with syntax like:
parent.topFrame.document.myForm.textField.value...
The parent object is actually the base HTML doc where the frameset is 
defined, so you're stepping up one level in the DOM and back down to 
the source in the other frame.
So we could have something like this in test2.html:
<BODY>
<FORM name="topFrameForm">
<input type="text" name="text1" value="Testing">
</FORM>
</BODY>
and something like this in test3.html:
<HEAD>
<SCRIPT language="JavaScript">
function getTopValue()
{
alert(parent.topFrame.document.topFrameForm.text1.value);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="bottomFrameForm">
<input type="button" value="Get Top Value" onClick="getTopValue()">
</FORM>
</BODY>
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com