I'm having difficulty in referring to a field in a form from another window. I'm not very familiar with JavaScript and could use some help to point me in the right direction.
I have a main page with two frames. Both frames open when the page is loaded. The first frame is named "frame1" and contains a form "form1" with a text field. Both the name and ID of the field are set to "field1". The second frame is named "frame2" and contains a link that is supposed to change the value of the field in frame1.
I have been able to get a pointer to frame1 from frame2 by using top.document.getElementsByTagName("frame1"). I assume that getting a pointer to the form field is done by using document.getElementById("field1").
However, I have no clue on how to combine these two together and to reference the field from frame2? top.document.getElementsByTagName("frame1").document.getElementById("field1") is not working.
Unless you have a custome tag called "frame1", I don't see how this would work at all. Are you sure this is what you are using, and it is not a typo in your post?
It would be appreciated if you would post a link to a web page, or post the actual code that creates the frameset and each of the pages referenced by the frameset.
Generally, referencing one frame from another is not that hard once you understand the heirarchy. "window.top" points to the top-most window containing the web page. From your description, that would contain two windows, one named "frame1" and one named "frame2". So for "frame2" to reference "frame1" you should be able to use "window.top.frame1.document.getElementById('field1')", assuming that there is an object with ID="field1" in "frame1" and there are no javascript errors in other parts of the page that are causing the script to fail.
Bookmarks