JavaScript: "form.item is not a function" in FramesetMge.js - Firefox

Topics: Developer Forum
Jun 16, 2008 at 1:26 AM

In the FramesetMge.js file there is code for finding the "form" element of a specific Frame and then either creating some hidden inputs or setting the values of the inputs (see code below).  In IE7 this code appears to run fine (no errors), but it bombs in Firefox stating "form.item is not a function" (full error message et end of this post). 

Here is a fuller sample of the script:

Calling Function

 // Set the values in hidden fields in m_postableForm, then post that frame.
// Returns true only if the form is submitted.
function FM_DoPost( bIsRetry )
{
    this.DebugLog("DoPost: Begin. isRetry = " + bIsRetry);
   
    // If there is already a post in progress, then do nothing right now.
    if ((this.m_postInProgress) && (bIsRetry != true))
    {
        this.DebugLog("DoPost: End. Post in progress.");
        return false;
    }
    this.m_postInProgress = true;
   
    // If this.m_postableForm isn't set (as can happen in some race conditions with hidden and
    // content frames), try to get the form from the m_frameName
    var form = this.m_postableForm;
   
    if (form == undefined)
    {
        try
        {
            form = window.top.frames[MAIN_FRAME].document.getElementById(this.m_postFrameName).contentWindow.document.forms[0];
        }
        catch (e) {
            // do nothing
            //aleart(e);
        }
   
        // If the form is still not defined, it probably indicates the frame is still loading. In this case,
        // it obviously cannot be posted, so wait a bit of time and try again.           
        if ((form == undefined) || (form == null))
        {
            // This probably indicates the frame is still loading, in which case we obviously cannot post it.
            g_retryCount++;
            if (g_retryCount < MAX_RETRY)
            {
                setTimeout("API_GetFramesetManager().DoPost( true )", 500);
                this.DebugLog("DoPost: End. Try again.");
            }
            else
            {
                this.DebugLog("DoPost: End. ** MAX RETRY count exceeded.");
            }
            return false;           
        }
    }
    g_retryCount = 0;
       
    this.DebugLog("\tDoPost: commands: " + this.m_commandMgr.GetCommands());
    this.DebugLog("\tDoPost: commandData: " + this.m_commandMgr.GetCommandData());
    this.DebugLog("\tDoPost: dataModelValues: " + this.m_dataModelValues);
    // Set the values in hidden controls
    SetHiddenControl( form, "hidCommand", this.m_commandMgr.GetCommands());// <-- Calls Function with Error
    SetHiddenControl( form, "hidCommandData", this.m_commandMgr.GetCommandData());// <-- Calls Function with Error
    SetHiddenControl( form, "hidAttemptId", this.m_attemptId);// <-- Calls Function with Error

    
    if (this.m_view == 0)   // Only post data if this is Execute view.
    {
        SetHiddenControl( form, "hidDataModel", this.m_dataModelValues );// <-- Calls Function with Error
        SetHiddenControl( form, "hidObjectiveIdMap", this.m_objectiveIdMap );// <-- Calls Function with Error

    }
      
    var formSubmitted = false;
    try
    {
        // Submit the form
        form.submit();   
        formSubmitted = true;
    }
    catch(e)
    {
        alert(L_FormSubmitFailed_TXT);
       
    }
   
    if (formSubmitted)
    {
        // Clear memory of submitted data
        this.m_dataModelValues = null;
        this.m_command = null;
        this.m_commandData = null;
        this.m_objectiveIdMap = null;
        this.m_contentFrameErrorTitle = null;
        this.m_contentFrameErrorMessage = null;
        this.m_contentFrameErrorAsInfo = false;
        this.m_framesRegistered[this.m_postFrameName] = false;
        this.m_commandMgr.ClearCommands();
    }
    else
    {
        this.m_postInProgress = false;
        this.WaitForContentCompleted(0);    // not waiting for anything
        this.ResetActivityId(); // fix TOC to show the activity id before this request
    }
   
    this.DebugLog("DoPost: End. Form submitted. Form action: " + form.action);
    return formSubmitted;
}

 

Function Being Called (and one with issue)

// Set the hidden control with the specified 'ctrlName' to have the 'ctrlValue'.
// If the control doesn't already exist in the form, create it.
function SetHiddenControl( form, ctrlName, ctrlValue )
{
    var ctrl = form.item(ctrlName); //<-- ERROR HERE IN FIREFOX (form.item is not a function)
    if ( ctrl == null )
    {
        var elInput = form.ownerDocument.createElement("input");
        elInput.type = "hidden";
        elInput.id = ctrlName;
        elInput.name = ctrlName;
        if (ctrlValue == null)
            elInput.value = "";
        else
            elInput.value = ctrlValue;
        form.appendChild( elInput );
    }
    else
    {
        if (ctrlValue == null)
            ctrl.value = "";
        else
            ctrl.value = ctrlValue;
    }
}


I have tried everything I can think of and have Googled this to death with no resolution thus far.  If you have any ideas, PLEASE let me know.

Full Firebug Error Message

form.item is not a function
FindActivityId(undefined)Toc.js (line 9)
SetCurrentElement("126")Toc.js (line 112)
FM_RegisterFrameLoad("frameToc")FramesetMgr.js (line 199)
body_onload()Toc.aspx (line 27)
onload(load )Toc.aspx (line 1)
 var ctrl = form.item(ctrlName);

Jun 16, 2008 at 6:16 PM
The fix was to change " var ctrl = form.item(ctrlName);   " to " var ctrl = form[ctrlName]; "
Oct 25, 2008 at 5:04 AM
I have just hired Richard Willis from SalamanderSoft Limited to finish the UI updates to the WebPlayer so it supports IE, FireFox, Safari, and hopefully Opera and Chrome as well. Once he has completed the updates and have everything working in the prior mentioned browser, he will move the updates into this projects source code for all to enjoy. I want to take a moment to thank those who have responded to my offer to pay for these updates and especially to thank Richard since he is giving up vacation time to do the work. 

Robert J Collins, 
Brisinger Group, inc.