1 Reply Latest reply on Mar 16, 2017 1:16 PM by grossmisconduct

    change table cell based on a textbox value, per page


      Hi! I am totally new to InDesign scripting. I have some understanding of PHP but not much Javascript. My knowledge as of now is based on Keith Gilberts course at Lynda.


      So I have this textbox with a header at the top of my page, and I have this table where one of the cells equals the header. I would like this cell to have a fillcolor. I have made this little script mixing two scripts I found here:find a text frame on the page with script label and here: How to apply a table cell style based on grep search? Thanks to the authors. As of now, I have managed the basic. The problem is that all the tables on every page gets filled with the last pages header rather than their respective pages headers. I have tried changing how much is inside my loop, but my unqualified guess would be that the problem is due to the fact that app.findTextPreferences is global and not per page.


      Actually, I was kind of proud of myself managing to select a cell based on another objects value, but now I need some help to get all the way there and maybe learn some more scripting in the process. Anyone have any suggestions on how to solve this problem?

        • 1. Re: change table cell based on a textbox value, per page
          grossmisconduct Level 1

          here is my script:


          var myDoc = app.activeDocument;

          var pagesLength = myDoc.pages.length;

          // Loop through all pages...

          for ( var i = 0; i < pagesLength; i++ ) {

          var myLabel = "topHeader",       // change to label

                myTextFrames =myDoc.textFrames.everyItem().getElements().slice(0),

                l = myTextFrames.length, 



          while (l--) { 

              if (myTextFrames[l].label != myLabel) continue; 

              myVariable = myTextFrames[l].contents; 

              break; // presuming there's only one "Foo" labeled frame on the page 

              // Otherwise you'll nead an array 






          app.findTextPreferences = app.changeTextPreferences = null;

          app.findTextPreferences.findWhat = myVariable;

          var myFound = myDoc.findText()



          for(i=0; i<myFound.length; i++)


              if(myFound[i].parent.constructor.name == "Cell")



             myFound[i].parent.appliedCellStyle = "Yellow"

              //  var overrides = myFound[i].clearOverrides()          //this is the new line added in this content