Jump to content

Syntax: Variable used to ID Object Prop


watagal

Recommended Posts

GreetingsI've been fussing and researching this all night. What is the syntax for including a variable (sFrameName) in the following:

 var oDiv = top.+sFrameName+.getElementById('divXX');

Thanks

Link to comment
Share on other sites

GreetingsI've been fussing and researching this all night.  What is the syntax for including a variable (sFrameName) in the following:
 var oDiv = top.+sFrameName+.getElementById('divXX');

Thanks

Without knowing what sFrameName is in Your case, I think:
var oDiv = top.sFrameName.document.getElementById('divXX');

but can't be sure without seeing more code. if sFrameName is parent window try:

var oDiv = window.opener.document.getElementById('divXX');

Anyway, it must allways be document.getElementById

Link to comment
Share on other sites

var oDiv = top.var oDiv = window.opener.document.getElementById('divXX');

Sorry, "sFrameName" is the name of a frame in the frameset. I'm trying to access the a <div> element across frames. I tried your first example: top.sFrameName.document.getElementById('divXX') - but I get the error: "sFrameName has no properties"Any other ideas?Thanks
Link to comment
Share on other sites

please post ALL your code or provide a link so we can see how your frames are setup.I am thinking you will need to do something like this.

parent.document.frames['framename'].document.getElementById('divid')

The frame must contain name= as well as id= for this to work. if you did this

parent.document.getElementById('frameid').document.getElementById('divid')

You would get an error (not usre why, in IE anyways)

Link to comment
Share on other sites

please post ALL your code
parent.document.frames['framename'].document.getElementById('divid'parent.document.getElementById('frameid').document.getElementById('divid')

Thanks again,Here's my main.htm framesets:
<frameset framespacing="0" border="0" frameborder="0" rows="75,*,25">    <frame id="frmHeader" name="frmHeader" scrolling="no" noresize target="main" src="SupportPages/header.htm" marginwidth="0" marginheight="0">    <frameset cols="200,*">        <frame id="frmToc" name="frmToc" src="SupportPages/toc.htm" marginwidth="0" marginheight="0" scrolling="auto" target="_self">        <frameset rows="101,*,10">            <frame id="frmTopicHeader" name="frmTopicHeader" src="SupportPages/login_header.htm" scrolling="yes" marginwidth="0" marginheight="0" target="_self">            <frame id="frmTopicMain" name="frmTopicMain" src="SupportPages/login_main.htm" marginwidth="0" marginheight="0" scrolling="yes" target="_self">            <frame id="frmComment" name="frmComment" src="SupportPages/comments.htm" marginwidth="0" marginheight="0" scrolling="no" target="_self">        </frameset>    </frameset>        <frame id="frmFooter" name="frmFooter" src="SupportPages/footer.htm" marginwidth="0" marginheight="0" scrolling="no" noresize target="_self">    <noframes>    <body>        <p>This page uses frames, but your browser doesn't support them.</p>    </body>    </noframes></frameset>

Here's my JS code:

function togPanel(sFrame,sDivID) {if (sFrame != "none") {//var oDiv = parent.document.getElementById(sFrame).document.getElementById(sDivID);var oDiv = parent.document.frames[sFrame].document.getElementById(sDivID);} else {var oDiv = document.getElementById(sDivID);}oDiv.style.display = (oDiv.style.display == "none") ? "block" : "none";}

here's my html code which calls the above function:

<span onclick="togPanel('frmToc','divToc');" style="cursor: pointer">TOC<span>

I still get error: "Error: parent.document.frames has no properties" in both IE and FF. Any ideas?thanks again.

Link to comment
Share on other sites

is the js code and the html call code in the main.htm page aswell??? If not what page are they on....this is very important to make it work.

No, the frameset are in main.htm and ths JS function togPanel() is defined in another htm file which is subsequently loaded into one on the frames.Does this help clerify things?TY
Link to comment
Share on other sites

I need you to post ALL the code for ALL the pages in the frameset includeing the frameset page. This is everything between and includeing <html>...</html>.Bits and pieces are not much good, we need everything to know how it works together.Where the javascript is makes a big difference in the way it is written.

Link to comment
Share on other sites

I need you to post ALL the code for ALL the pages in the frameset ......
Here's main.htm
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Notebook</title></head><frameset framespacing="0" border="0" frameborder="0" rows="75,*,25">	<frame id="frmHeader" name="frmHeader" scrolling="no" noresize target="main" src="SupportPages/header.htm" marginwidth="0" marginheight="0">	<frameset cols="200,*">		<frame id="frmToc" name="frmToc" src="SupportPages/toc.htm" marginwidth="0" marginheight="0" scrolling="auto" target="_self">		<frameset rows="101,*,10">			<frame id="frmTopicHeader" name="frmTopicHeader" src="SupportPages/login_header.htm" scrolling="yes" marginwidth="0" marginheight="0" target="_self">			<frame id="frmTopicMain" name="frmTopicMain" src="SupportPages/login_main.htm" marginwidth="0" marginheight="0" scrolling="yes" target="_self">			<frame id="frmComment" name="frmComment" src="SupportPages/comments.htm" marginwidth="0" marginheight="0" scrolling="no" target="_self">		</frameset>	</frameset>	<frame id="frmFooter" name="frmFooter" src="SupportPages/footer.htm" marginwidth="0" marginheight="0" scrolling="no" noresize target="_self">	<noframes>	<body>	<p>This page uses frames, but your browser doesn't support them.</p>	</body>	</noframes></frameset></html>

Here's login_main.htm

<html><head><meta http-equiv="Content-Language" content="en-us"><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Topic Main</title><base target="_self"><script language="JavaScript">	<!--//	function togPanel(sDivID) {		var oDiv = document.getElementById(sDivID);		oDiv.style.display = (oDiv.style.display == "none") ? "block" : "none";	}	function togPanel2(iFrame,sDivID) {		if (iFrame != -1) {//			var oDiv = parent.document.getElementById(sFrame).document.getElementById(sDivID);			var oDiv = parent.document.frames[iFrame].document.getElementById(sDivID);		} else {			var oDiv = document.getElementById(sDivID);		}		oDiv.style.display = (oDiv.style.display == "none") ? "block" : "none";	}	//--></script></head><body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0"		style="text-align: left" bgcolor="#000000">				<table border="0" width="100%" id="table7" cellspacing="0" cellpadding="0">					<tr>						<td valign="top">						<p style="margin: 6px 3px" align="left">						<span onclick ="togPanel('divRegister')" style="cursor: pointer">						<font color="#99CCFF" size="2" face="Tahoma">						Register Now</font><font color="#FFFFFF" size="2" face="Tahoma">						</font>						</span>						<font size="2" face="Tahoma"><font color="#FFFFFF">  --  						It's free!  						</font> 						<span onclick="togPanel2(1,'divToc');" style="cursor: pointer">							<font color="#99CCFF">TOC</font><font color="#FFFFFF"> </font>						</span>						</font></p>						<div id="divRegister" style="display:none">						<form method="POST">							<p style="margin: 6px 3px" align="left">							<table border="1" width="95%" id="table8" bgcolor="#EFFEEB">							<tr>								<td>							<table border="0" cellpadding="0" cellspacing="0" width="100%" id="table9">								<tr>									<td width="10" align="left" height="10"></td>									<td width="479" height="10">									<p align="left"></td>								</tr>								<tr>									<td width="10" align="left"> </td>									<td width="479">								<p align="left">								<input name="txtFirstName" size="20" type="text" value="First Name"><input name="txtLastName" size="20" type="text" value="Last Name"></td>								</tr>								<tr>									<td width="10" align="left"> </td>									<td width="479">								<p align="left">								<input name="txtCompany" size="41" type="text" value="Company Name"></td>								</tr>								<tr>									<td width="10" align="left"> </td>									<td width="479">								<p align="left">								<input name="txtEmail" size="60" type="text" value="Email Address"></td>								</tr>								<tr>									<td width="10" align="left"> </td>									<td width="479">								<p align="left">								<input name="txtEmail2" size="60" type="text" value="Email Address - Confirm"></td>								</tr>								<tr>									<td width="10" align="left"> </td>									<td width="479"> </td>								</tr>								<tr>									<td width="10" align="left"> </td>									<td width="479">								<p align="left">								<input name="txtLoginName" size="30" type="text" value="Login Name"></td>								</tr>								<tr>									<td width="10" align="left"> </td>									<td width="479">								<p align="left">								<input name="txtPassword1" size="30" type="text" value="Password"></td>								</tr>								<tr>									<td width="10" align="left"> </td>									<td width="479">								<p align="left">								<input name="txtPassword2" size="30" type="text" value="Password - Confirm"></td>								</tr>								<tr>									<td width="10" align="left"> </td>									<td width="479">									<p align="right">							<input type="submit" value="Register" name="btnRegister">							<input type="reset" value="Reset" name="btnRegisterReset"></td>								</tr>							</table>								</td>							</tr>						</table>						</p>						</form>						</div>						</td>					</tr>					</table>				</body></html>

These are the 2 file, thanks for taking a look at them

Edited by aspnetguy
Link to comment
Share on other sites

Thanks all - I got it to work with:

function togPanel(sFrame,sDivID) {	if (sFrame != "") {		var oDiv = window.parent.frames[sFrame].document.getElementById(sDivID);	} else {		var oDiv = document.getElementById(sDivID);	}	oDiv.style.display = (oDiv.style.display == "none") ? "block" : "none";}

"sFrame" var can either be the frame's index number or the 'name' or 'id' property in the <frame> element. This navigates across frames to toggle a <div> element on/off Thanks for pointing me in the right direction.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...