469,293 Members | 1,585 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,293 developers. It's quick & easy.

Debug my javascript issue with forms and frames

You can consider me an amature. I can't figure this one out. Hopefully, I can explain it well enough.

Here's the structure of my page:

***myASPpage.asp***
(contains a frame inclosed in a div)
<frame id=myFrame>
|
V

***mySearch.asp***
(contains a form with two select fields)
<form id=searchForm>
fields: model & serial
|
V

***myScript.asp***
(a script that populates the serial field with distinct serial numbers based on the model number choosen)

On this page, I'm trying to reference the "serial" field from "searchForm" and get it's length using this code:

Expand|Select|Wrap|Line Numbers
  1. parent.frames['myFrame'].document.form('searchForm').getElementById('serial').options.length;


But, it gives me "null or object not found". Oddly, I've gotten my code to work perfectly fine if I don't use an iFrame and keep all the code from "myScript.asp" on the same page as "mySearch.asp". So, I'm thinking I'm not doing something correctly due to the frame.
Mar 1 '11 #1

✓ answered by acoder

That line of JavaScript is invalid syntax. Either try:
Expand|Select|Wrap|Line Numbers
  1. parent.frames['myFrame'].document.forms['searchForm'].serial.options.length;
or if serial has an ID:
Expand|Select|Wrap|Line Numbers
  1. parent.frames['myFrame'].document.getElementById('serial').options.length;

4 1494
acoder
16,027 Expert Mod 8TB
That line of JavaScript is invalid syntax. Either try:
Expand|Select|Wrap|Line Numbers
  1. parent.frames['myFrame'].document.forms['searchForm'].serial.options.length;
or if serial has an ID:
Expand|Select|Wrap|Line Numbers
  1. parent.frames['myFrame'].document.getElementById('serial').options.length;
Mar 2 '11 #2
Thanks for the reply. I'm still getting the error:

Message: 'parent.frames.myFrame.document' is null or not an object


I've read tons of tutorials on these tree structures, but I guess I'm still missing something.
Mar 2 '11 #3
acoder
16,027 Expert Mod 8TB
myFrame should be the name of the frame:
Expand|Select|Wrap|Line Numbers
  1. <frame name="myFrame" ...>
Mar 2 '11 #4
I figured it out. Your original solution was correct minus one small thing (on my end). The last script (asp page) was opening as new window. So I had to use:

"opener" instead of "parent"
Mar 2 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by William.R.Reisen | last post: by
4 posts views Thread by Andrew Clark | last post: by
2 posts views Thread by apngss | last post: by
1 post views Thread by yma | last post: by
2 posts views Thread by Dinh Bao Tuyen | last post: by
4 posts views Thread by dotcom | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.