4 Replies Latest reply on Dec 11, 2016 6:13 PM by nicolec26875103

    Spawning pages messes with my javascript!

    nicolec26875103

      Hi everyone,

       

      I am self taught with javascript and adobe so please bear with me!

       

      I have just finished making a massive form which on the second page there is a list of questions with yes or no for the answer and if they click Yes it spawns a template page which they can fill out, then go back and continue to next question. 

       

      Problem is, on these templates I have javascripts that include the names of the fields.  When the page spawns, it changes the name of the fields and then the javascript doesnt work.  Is there anyway to overcome this problem? HELP PLEASE   Thanks so much in advance!

        • 1. Re: Spawning pages messes with my javascript!
          George_Johnson MVP & Adobe Community Professional

          Yes, there is a way to deal with this. If you post one of the scripts you're having trouble with, we should be able to suggest changes to it.

          • 2. Re: Spawning pages messes with my javascript!
            gkaiseril MVP & Adobe Community Professional

            A Lesson in Templates shows how fields are renamed during spawning pages with the 'bRename" parameter set to true.

             

            The fields of the template are prefixed with "P[#}.[emplateName]."  If one uses the "event.target.name" property of the field name, the string value can be parsed to obtain the field's name split by the "." character. The first element of the array will be the "P[#}" value and the second element will be the template name. One then only needs to compute the prefix string which can be added to any field's template source name on the spawned page to obtain the full name of the field on the spawned page. I would create a document level function to generate this prefix string if the field has an altered name as part of the spaqning. If the field's name has not been altered then return a null stirng. This approach will allow one to workout the necessary scrpts on the template and easily add the prefix string if needed.

            • 3. Re: Spawning pages messes with my javascript!
              nicolec26875103 Level 1

              Thank you,

               

              Example of my question is, I have a question with a Yes/No answer,  If they click no, the next questions under it are grey and read only so they know they don't have to answer those questions.  If they click yes I have it so they change to black and fillable so that they know they need to answer those questions.  the javascript I used for this is:

              It's probably the wrong way to do it, but like I said I am self taught so its the best I could do haha

               

              var myRad = getField("16");

               

               

              if(myRad.value == "Yes")

              {

              getField("Total Floor area").textColor = color.black;

              getField("m").textColor = color.black;

              getField("m2").textColor = color.black;

              getField("Height:").textColor = color.black;

              getField("Percentage of overall floor space:").textColor = color.black;

              getField("%1").textColor = color.black;

              this.getField("Floor area").readonly = false;

              this.getField("heights").readonly = false;

              this.getField("% of floor").readonly = false;

              }

               

              Thanks in advance

              • 4. Re: Spawning pages messes with my javascript!
                gkaiseril MVP & Adobe Community Professional

                If you used the rename option when calling the spawn method, you have not accounted for the addition of the "P#.templateName." being prefixed onto the fields on thw spawned pages