SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem passing variables in frameset

    I have to recreate an old quiz that ran on our servers, and redo it so that it runs in Javascript from a CD.

    It works in a very simple way - five pages of questions, each page passes some values to arrays in the parent frameset, and the final score page displays the results (which it gets from the parent). It's very old code and was only written to work with IE5.5 at the time.

    I'm finding some strange results. In IE5.5 it doesn't get beyond page 2 and gives an error message saying the 'object doesn't support a property'; in Firefox it doesn't get beyond page 1, and IE6 gets to page 4 before stopping with the 'object doesn't support a property' message. Yet the code is pretty much identical on every page.

    One source of contention seems to be referring to the form. The original code just referred to form1.elements.length. In order to make that work in Firefox I added a line form1=document.getElementById('form1') immediately before, but IE seems to dislike that.

    I've posted it at http://www.nlamont.force9.co.uk/demo...g/frameset.htm and I'd be grateful if anyone can cast light on it. It still has to work in IE5.5 unfortunately, as well as 6 and Firefox but it we don't have to support IE7 yet.

  2. #2
    SitePoint Addict jtrelfa's Avatar
    Join Date
    Oct 2004
    Location
    Troy, Mi
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of:

    "form1.elements.length"

    Have you considered:

    "document.form1.elements.length"
    or
    "document.forms[0].elements.length"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll try that - thanks.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's working now (at the same address). Thanks for the tip. What I did:

    var len=document.forms[0].elements.length
    var theform=document.forms[0]
    for (i=0;i<=len-2;i++) {
    if (theform.elements[i].checked){
    v=eval(theform.elements[i].value) // value returned by question
    n=theform.elements[i].name // name of question
    z=n.substring(0,1) //check if first or second grp
    ....etc

    So I took your advice about the way to refer to the form, and also changed the variable I used to 'theform' instead of 'form1' which was the same as the ID of the form itself. I also found that one page had a comment somehow placed right in the middle of the doctype declaration. That stopped IE5.5 in its tracks, but not the others.

    Thanks again for your help, now I just have to tidy up the look of it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •