Debug my javascript issue with forms and frames

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sammy vang
    New Member
    • Mar 2011
    • 3

    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.as p***
    (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:

    Code:
    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.a sp" on the same page as "mySearch.a sp". So, I'm thinking I'm not doing something correctly due to the frame.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    That line of JavaScript is invalid syntax. Either try:
    Code:
    parent.frames['myFrame'].document.forms['searchForm'].serial.options.length;
    or if serial has an ID:
    Code:
    parent.frames['myFrame'].document.getElementById('serial').options.length;

    Comment

    • sammy vang
      New Member
      • Mar 2011
      • 3

      #3
      Thanks for the reply. I'm still getting the error:

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


      I've read tons of tutorials on these tree structures, but I guess I'm still missing something.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        myFrame should be the name of the frame:
        Code:
        <frame name="myFrame" ...>

        Comment

        • sammy vang
          New Member
          • Mar 2011
          • 3

          #5
          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"

          Comment

          Working...