Expand my Community achievements bar.

SOLVED

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

Avatar

Level 3

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");


    }


1 Accepted Solution

Avatar

Correct answer by
Level 10

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!

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

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!

Avatar

Level 3

You are so right and I was so blind! I miss working in an office with more developers! Thanks a million!