Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript and Frames

Status
Not open for further replies.

wdperson

Programmer
Joined
May 19, 2006
Messages
7
Location
US
Hello,

I am at my wits end with some code I am doing. I am working on a website that uses frames and has the following in a form. The code is as follows:

function codename() {
if(document.IntranetRegistration.chbxVirtual.checked)
{
document.IntranetRegistration.Address.disabled=true;
}
else
{
document.IntranetRegistration.Address.disabled=false;
}
}

I am referencing this code from the onClick event from the Checkbox named chbxVirtual inside the form. When I use the page If I explicitly link to this page (outside of frames) it works fine. If I put it inside a frame and try the check box it throws an error "object expected." I have tried other javascript code and it does the same thing: works outside of the frames, but doesn't work inside the frame and throws the exact same error. I am not sure if I need to put "parent.document....." in my code and throw the above function in the parent frame or not? Any ideas or help would be greatly appreciated.

thanks.
Mike
 
If the "IntranetRegistration" form is NOT in the same frame as the above code, then you will need to reference it differently. To give an more accurate answer, it would help to see your form hierarchy, but this might work...

Replace "document.IntranetRegistration." with "parent.nameOfFrameWithForm.document.IntranetRegistration."

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan,

Thanks for the help. The Hierarchy is as follows (this is bad, but I didn't do it this way):

Main page:
Intranet_frames.asp
----> contains frame layout with right side of page referencing intranet_main.asp

intranet_main.asp references the following code:
parent.load.location.href = "IntranetRegistrationFormFrames.asp"

intranetRegistrationFormFrames has an include directive:
<!-- #Include File=IntranetRegistrationForm.asp -->

IntranetRegistrationForm has the javascript code and form on it. When the code is executed in the frame it has the error object expected and references the intranet_main.asp page.

hope this helps? It's not what I would do had I designed this site.

thanks
Mike

 
If the form and the code function codename are in the same page or frame, it will not throw an error.

If the form and the code, function codename are in the different frames, some changes need to make:
in the form
onClick="...;parent.frameFunction.codename();..."
in the code, function codename ()
parent.frameForm.IntranetRegistration.Address.disabled=true

or,
in the form
onClick="...;parent.frameFunction.codename(this);..."
in the code, function codename (objForm)
objForm.Address.disabled=true

I hope this works.
 
Greetings!

I'm not exactly sure if I understand how you have your pages set up, but here is some code that I've used to access functions across frame pages...

If this is your frame definition:
Code:
<FRAMESET ROWS="120, *" FRAMEBORDER="NO">
<FRAME SRC="FV_Header.htm" NAME="winHeader" NORESIZE>

<FRAMESET COLS="265, *" FRAMEBORDER="NO">
<FRAME SRC="FV_Menu.htm" NAME="winMenu" NORESIZE>
<FRAME SRC="" NAME="winBody" NORESIZE>

</FRAMESET>
</FRAMESET>
... then from within the mane frame page, you can reference child frames this way...
Code:
winMenu.functionName(parms);
If you're in the child frame and you want to reference the main parent frame, try this:
Code:
parent.functionName(parms);
I'm not sure exactly what you would to to go from child frame to child frame, but I'm sure you could try a few things along the lines of what I've posted above and come up with something.

I hope that answers your question!


---------------------
He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
lol, I need to be quicker about posting. I come back in here and there are already three posts before mine.


---------------------
He who has knowledge spares his words, and a man of understanding is of a calm spirit. Even a fool is counted wise when he holds his peace; when he shuts his lips, he is considered perceptive. - King Solomon
 
Thanks for everyone's reply.

ashim2:
The form and the javascript are on the same asp page. Just for kicks, I used the code you suggested and it didn't resolve the problem. It gave an "undefined" error.

snotmare:
I tried the code you suggested also and it didn't resolve the problem.

Doing research an "object expected" error appears that it is a typographical error. Checking everything 10 times has not turned up any typographical/formatting errors.

Since the form that I am checking and the javascript code are physically located on the same page, is it even a frames issue?

thanks.
Mike
 
Dan,

Here is the main page that holds the frames. Thanks.

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>

</title>
<!-- #Include File=CheckSession.asp -->
</head>
<frameset ROWS="55,*,0,0" border="0">
<frame SRC="Intranet_header.asp" NAME="header" scrolling="no" noresize marginheight="0">
<frameset cols="225,15,*" border="0">
<frame id="navigation" SRC="blank.htm" NAME="navigation" scrolling="auto" noresize marginheight="0">
<frame SRC="blank.htm" NAME="spacer" scrolling="no" noresize marginheight="0">
<frame SRC="Intranet_main.asp" NAME="main" scrolling="auto" noresize marginheight="0">
</frameset>
<frame SRC="blank.htm" NAME="load" scrolling="yes" noresize marginheight="0">
<frame SRC="blank.htm" NAME="ext" scrolling="yes" noresize marginheight="0">
</frameset><noframes></noframes>

<!-- #Include File=ErrorOccurred.asp -->
</html>
 
Now I'm very confused.

You say you are running the "codename" function from a checkbox inside "the form" (presumably the one named "IntranetRegistration").

You also say that the include file "IntranetRegistrationForm.asp" "has the javascript code and form on it". The include file is included by the file "IntranetRegistrationFormFrames.asp", which is loaded into the frame named "load".

However, the "load" frame is hidden... so the question is:

Howe do you ever see the checkbox to check it? Have I mis-understood your explanation?

If the form named "IntranetRegistration" contains the checkbox (named "chbxVirtual"), and a field named "Address", and that form is in the same page as the js function "codename", then you shouldn't be seeing any problems.

Can you clarify any further?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan,

>You say you are running the "codename" function from a >checkbox inside "the form" (presumably the one >named "IntranetRegistration").

yes, this is correct.

I may have misspoke about the include file. This code is very hard to read and very disorganized. I believe it works such as this:

Intranet_frames.asp (which is the code with the frameset). Which has the "main" frame on the page. After reviewing the page I believe that the page that is loaded into "main" (Intranet_main.asp) may directly load the IntranetRegistrationFormFrames.asp page as opposed to loading it into the hidden frame. I determined this after reading the code a little more. It is very hard to follow, so I apologize for the confusion.

So, the hierarchy is:
Intranet_frames.asp -> intranet_main.asp -> intranetregistrationformframes.asp (loaded into the "main" frame) -> intranetregistrationform.asp

>If the form named "IntranetRegistration" contains the >checkbox (named "chbxVirtual"), and a field >named "Address", and that form is in the same page as >the js function "codename", then you shouldn't be seeing >any problems.

that is all true, but it is throwing the error "object expected." It references line 69, char 1 on intranet_main.asp. Looking at the intranet_main.asp page line 69 isn't even JavaScript. Breaking out of the frames (hitting page intranetregistrationform.asp) it works as it should.

thanks for your efforts so far.
Mike



 
Dan,

I actually tried that but the application doesn't even load the navigation structure to be able to navigate to the page that needs troubleshooting.

Mike
 
Dan,

Yes, actually I solved it. I fixed it yesterday as a matter of fact. I had put it down for awhile as I worked on other applications. For some reason (I hope someone can explain this to me). The actual javascript code had to be on the page that referenced the include file. In other words if you have 2 web pages. Main.html and another page other.html. If Main.html has a include directive that says to include "other.html" in the page, the javascript for a form on "other.html" cannot be on "other.html" it has to be on "main.html." Not sure why. The way my application worked was I had a form on "other.html" and I had javascript code to hide or show a part of the form using a radio button. As soon as I put the javascript code for hiding or displaying form elements on main.html it worked fine. The only reason I can think that it had to be programmed this way is due to the way the pages load? Not sure why it did this.

Any ideas? I think it may be the way the application was designed, but I may be wrong.....thanks for your help Dan, I appreciate it your efforts. It was very frustrating, but a very good learning experience. I have been meaning to have a better grasp on Javascript and I think this has been a good experience in accomplishing that.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top