4 Replies Latest reply on May 16, 2011 12:07 PM by gkaiseril

    Clear page button- yes and cancel?

    adamss14

      Hi all, I'm just learning javascript and could use some help.  I have an Acrobat PDF form with a clear page button on the top.  When the user clicks the button, I would like an alert to popup that says "Are you sure you wish to clear the page?".  If the user clicks "Yes", the page clears.  If the user clicks "No", the alert disappears and nothing else happens.  I don't know how to get the cancel button to work, but everything else works fine.  Here's my code:

       

      var clearbutton = app.alert({
      cMsg: "Are you sure you wish to clear the page?",
      cTitle: "Clear Page?",
      nIcon: 2, nType: 1
      });

       

      var iPage = pageNum;

       

      var sFields = new Array();

       

      for(var x=0;x<numFields;x++)

       

      {var pg = getField(getNthFieldName(x)).page;

       

      if((typeof pg == 'number' && pg == iPage) || (typeof pg != 'number' && pg.indexOf(iPage) > -1))sFields[sFields.length] = getNthFieldName(x);}

       

      if(sFields.length > 0)resetForm(sFields);

       

       

      How do I associate the cancel button (return of 2) with not continuing with the rest of the script? Thanks to anyone who can help out!!

        • 1. Re: Clear page button- yes and cancel?
          try67 MVP & Adobe Community Professional

          Place the code in a function and add this after the alert:

           

          if (clearbutton == 2) return;

          • 2. Re: Clear page button- yes and cancel?
            adamss14 Level 1

            Thanks for the reply.  I have spent the afternoon trying to figure this out (I warned you I am a beginner).  I'm obviously doing something wrong because this breaks my alert.  Would anyone be able to guide me a bit more? Thanks!

             

            function clearconfirm()
            {
            var clearbutton = app.alert({
            cMsg: "Are you sure you wish to clear the page?",
            cTitle: "Clear Page?",
            nIcon: 2, nType: 1
            });

            if (clearbutton == 2) return;

            }

            • 3. Re: Clear page button- yes and cancel?
              adamss14 Level 1

              If I do it this way, my alert works again, but still not getting the cancel button to work...

               

               

              var clearbutton = app.alert({
              cMsg: "Are you sure you wish to clear the page?",
              cTitle: "Clear Page?",
              nIcon: 2, nType: 1
              });
              function clearconfirm()
              {
                  if (clearbutton == 2) return;
              }

              • 4. Re: Clear page button- yes and cancel?
                gkaiseril MVP & Adobe Community Professional

                Try;

                 

                function ClearPage() {
                var clearbutton = app.alert({
                cMsg: "Are you sure you wish to clear the page?",
                cTitle: "Clear Page?",
                nIcon: 2, nType: 1});
                if (clearbutton == 1) {
                   // "OK" selected
                   var iPage = this.pageNum;
                   var sFields = new Array();
                   var pg;
                   // loop through all fields and find fields on page
                   for(var x=0; x < numFields; x++){
                      pg = this.getField(getNthFieldName(x)).page;
                      if((typeof pg == 'number' && pg == iPage) || (typeof pg != 'number' && pg.indexOf(iPage) > -1))
                         sFields[sFields.length] = getNthFieldName(x); // fill array of field names
                   } // end for loop numFields
                   // clear the field names
                   this.resetForm(sFields);
                } // end if 'OK"
                // if anything other than "OK" nothing done
                return;
                } // end ClearPage funciton

                // call the ClearPage function
                ClearPage();