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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing form from another frame as a function parm

Status
Not open for further replies.

dpsuns

MIS
Jan 2, 2001
2
US
I have a frameset with 2 frames named "FrameA" and "FrameB". FrameA contains a form named "myForm". FrameB has a button with an OnClick event that calls a JS function named "myFunction". myFunction must be passed the form from frame "A" as a parameter. I've tried:

OnClick="myFunction(top.FrameA.document.myForm);"

but get an "object not found" error when the function executes.

What's wrong?

 
that should work (I think). can you give us a link to the pages this is for? Maybe something in the body of myFunction is messing it up jared@aauser.com
 
try 'parent' maybe instead of top, or '_top'.I have never seen the "Object not found" error (?)

-Ben. "Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer"
 
C'mon Ben, top is a perfectly valid object. Don't go misdirecting here.

Either "frameA" or "myForm" have not been declared. Make sure that those objects exist. Make sure the names are the same, including case.

Would you have to use document.forms.myForm? You could try that; I'm not sure if you can reference a form directly from the document or if you have to use the "forms" object.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
you do not need to use the forms array to access a form:

document.formname

is sufficient jared@aauser.com
 
After much trial & error, the "object not found" message only goes away when I omit the parent / top reference altogether (the document reference as shown in my original message turns out to be optional). In other words, these are the only two formats that make the call:

OnClick="myFunction(FrameA.myForm);"
or
OnClick="myFunction(FrameA.document.myForm);"

Now on to the next problem. When "myFunction" executes, it makes references to form elements being passed, such as:

var textValue = theForm.textField.value

Now I get an error "textField is not an object". It's acts as if it can't find the form elements.
 
try document.theForm.textField.value jared@aauser.com
 
Have you given the textfield an id?

eg

<FORM id='theForm' action etc>
<INPUT type=text value='mytext' id='textField' name='textField'>


</FORM>

This should make it visible.
 
does OnClick=&quot;myFunction(FrameA.document.myForm);&quot; work in both IE and NS? I thought that IE would assume the parent like that, but not NS.

Also, there's no reason why top.FrameA would cause a problem, unless maybe you declared another variable named top? It doesn't make much sense to me. But, I guess if you got it working, then you don't care much if it should work, as long as it does work, right? ;-)

No offense, but it sounds like you have something written sloppily early on in the code to cause all of these weird errors. Maybe if you can post more code, we can see if there is a simple solution in how you are defining everything.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top