title: Use for loop to search an array of fields to find & replace text
body: <p>I have created an XFA form using Adobe Designer (LiveCycle) which utilizes 25 textfields. I am trying to create a 'Redact' button which, when pressed, will iterate through the 25 fields and search for a name in the string value of each field. If the name is found then it replaces the name with &quot;********&quot; using a global RegExp and if not, moves on to the next field. This is what i've come up with so far, but it isn't working. Can anyone help?</p>
  <pre><code>var name = nameGlobal.value.toString();
   var regExp = new RegExp(name, &quot;gi&quot;);
   var fields = [
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].N_Location.F1.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].N_Witnesses.Notes_2.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].F2.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_4.TextField7&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_5.TextField7&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_6.TextField9&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_7.N_7_2.TextField10&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_7.N_7_4.TextField11&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_7.N_7_6.TextField12&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_7.N_7_8.TextField13&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_7.F4.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F5.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F6.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F20.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.PupilSize.F7.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F8.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F9.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F10.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.F11.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_8.ClinicalNOtes.#subform[20].TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_9.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Notes_10.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].F13.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].F14.TextField5&quot;).rawValue.toString(),
    xfa.resolveNode(&quot;form1.#subform[3].#subform[4].Msic_Notes.TextField5&quot;).rawValue.toString()
  ];
  
   for (i = 0; i &lt; fields.length; i++) {
      if (fields[i] !== null) {
      fields[i] = fields[i].replace(name, &quot;********&quot;);
       }
      }
  </code></pre>