Radio buttons fail to call a function... why?

ArrueiraVermelh

11-08-2015

Hello Everyone,

I am working on complex form that will require a lot of show/hide fields based on user input. I am trying to automate the behavior with a JavaScript function placed at the parent form level. In fact I already have a couple functions there and they work great. The one below is a mystery. If both function and function calls are placed in the same object (radio group) everything works great. The moment I move the function to my parent form script object nothing works. Any ideas what I am missing?

Thanks,

Raquel

XMP.ApplicantForm.#variables[0].toggleOptComment



// Hide/Show fields based on field name prefix (substring)


// sectionName = parent subform to hide/show fields (search range)


// endPosition = integer, position of last character to be searched in field name (initial position is always zero)


// prefixString = substring to find in field name


// presenceValue = "visible" or "hidden"



function toggleFields(sectionName,endPosition,prefixString,presenceValue) {



        var oFields = sectionName.nodes;


        var nNodesLength = oFields.length;


 


        for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {


            if (oFields.item(nNodeCount).name.substring(0,endPosition) == prefixString) {


                oFields.item(nNodeCount).presence = presenceValue;


        }


    }


}



XMP.ApplicantForm.S9.S9-Radio::change - (JavaScript, client)



/* Submit Section 9.1 */


if (this.rawValue == "Yes") {


    // Show these:


    toggleFields(this.parent,2,"S9","visible");


    // Hide these:


    toggleFields(this.parent,4,"S9_2","hidden");


    }


/* Submit Section 9.1 */


if (this.rawValue == "No") {


    // Show these:


    toggleFields(this.parent,4,"S9_2","visible");


    // Hide these:


    toggleFields(this.parent,2,"S9","hidden");


    }


Accepted Solutions (1)

Accepted Solutions (1)

Magus069

MVP

11-08-2015

Hi there,

to be able to call a function from a Script Object you must reference the Object itself to access to its functions..

So to be able to call toggleFields from any object in form from a Script Object you will have to call it this way:

Hope this help!