I am survey document. I have a button that when click loops through the questions and if it finds a certain value, it adds an instance to my "results" subform with the answer from the question.
function CreateSOD(parentSubform)
{
var allChildElements;
var intNumElements;
var currentElement;
var j;
var counter = 1;
//Get all the child nodes of the parent element
allChildElements = parentSubform.nodes;
//Total number of element in the object
intNumElements = allChildElements.length;
//Loop through all the child elements
for(j=0; j < intNumElements; j++)
{
currentElement = allChildElements.item(j);
if(allChildElements.item(j).className == "subform")
{
if(currentElement.name == "Section")
{
// grab all of the "not met" tags
if(currentElement.ddlChoice.rawValue == "2")
{
// add a new instance
TopmostSubform.SOD.SODSection.instanceManager.addInstance();
//set the text values
TopmostSubform.SOD.SODSection.all.item(counter).Reg.rawValue = currentElement.Reg.caption.value.text.value;
TopmostSubform.SOD.SODSection.all.item(counter).RegText.rawValue = currentElement.RegText.rawValue;
TopmostSubform.SOD.SODSection.all.item(counter).TextField.rawValue = currentElement.TextField.rawValue;
//debug info
console.println(currentElement.name + "[" + counter + "]");
counter++;
}
}
CreateSOD(currentElement);
}
}
}
The problem I am having, is that if the user clicks the button again, the index of the results subform changes and the values get all messed up.
I've looked everwhere, but I need to remove all instances of the results subform, then repoulate it using the script above. I've tried using setInstances(), removeInstances() etc and I seem to be missing something.
Anyone know how to "reset" the instances before I do the looping and adding?
Many Many Thanks!