Announcement

Collapse
No announcement yet.

Using a checkbox to toggle (show / hide) specific pages

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using a checkbox to toggle (show / hide) specific pages

    Hello, I'm trying to create fillable form and in total it's going to be around 30 pages. Since not everyone will need to fill out each page, I wanted to have a table of contents and use a checkbox for certain subjects that would show/ hide pages needed, or not needed. Is this possible? I've added a test document to give a better visual. Thanks in advance for any help, or suggestions.
    Attached Files

  • #2
    You will find this topic helpful: https://forums.foxitsoftware.com/for...is-not-checked

    Comment


    • #3
      Originally posted by JRB View Post
      Thank you. I did come across that and tried to review the demo file to see if I could apply the same properties (change java code) and I have figured it out yet. I'm not overly familiar with JavaScript, so i'm certain that has something to do with my struggles. I'd definitely welcome any advice, or tips. Thanks again

      Comment


      • #4
        pumademon

        Normally we could browse to the page then go to Form->Page Template and add the page as template to be shown/hidden; Then we could right-click on the checkbox->Actions->Run a JavaScript->then add JS.
        See attached that I've added the JS to your test document.
        Attached Files

        Comment


        • #5
          Selector name for checkbox is same as the component which is utilized to show the. content.
          CSS show property of every component is set to none utilizing show: none; for concealing the component at first.
          Use . switch() strategy for showing and concealing the component for checking and unchecking the container.

          Comment


          • #6
            Shams21
            Sorry I don't quite understand what you encountered, to avoid misunderstanding, could you please clarify what seems to be the problem?

            Comment


            • #7
              Originally posted by cherry View Post
              pumademon

              Normally we could browse to the page then go to Form->Page Template and add the page as template to be shown/hidden; Then we could right-click on the checkbox->Actions->Run a JavaScript->then add JS.
              See attached that I've added the JS to your test document.
              Hi Cherry, Thank you for this! When I tick the checkbox, the extra page (template) does appear. I have 2 additional questions that I hope you might be able to help with.

              1. After ticking the checkbox, the template appears, however when I "untick" the checkbox, the additional template is still there. Is there a way to remove when "unticking" the checkbox, or should a 2nd checkbox for "no" be created that would hide the template?
              2. When ticking the checkbox for the additional template page, is there a way to assign placement in the .pdf? For example, if the additional information page 1 checkbox is ticked "yes", can that specific template be a specific page (i.e. pg 5) instead of being added to the end of the .pdf?

              Thank you for you're help with this, it's greatly appreciated.

              Comment


              • #8
                1. Yes
                2. It's easier to delete all the spawned pages each time and to re-spawn in order only those that are checked.

                See attached sample file, it uses this script:
                Code:
                function managePages() {
                // remove all previously spawned pages
                if (this.numPages > 1) {this.deletePages({nStart: 1, nEnd: this.numPages-1});}
                // spawn checked page(s)
                if (this.getField("Additional Company Branch 1").value != "Off") {this.getTemplate("AdditionalCompanyBranch1").spaw n(this.numPages, false, false);}
                if (this.getField("Additional Company Branch 2").value != "Off") {this.getTemplate("AdditionalCompanyBranch2").spaw n(this.numPages, false, false);}
                if (this.getField("Additional Company Branch 3").value != "Off") {this.getTemplate("AdditionalCompanyBranch3").spaw n(this.numPages, false, false);}
                if (this.getField("Additional Contacts 1").value != "Off") {this.getTemplate("Additional Contacts 1").spawn(this.numPages, false, false);}
                if (this.getField("Additional Contacts 2").value != "Off") {this.getTemplate("Additional Contacts 2").spawn(this.numPages, false, false);}
                if (this.getField("Additional Contacts 3").value != "Off") {this.getTemplate("Additional Contacts 3").spawn(this.numPages, false, false);}
                // go back to first page
                this.pageNum = 0;
                }
                Attached Files

                Comment


                • #9
                  Originally posted by JRB View Post
                  1. Yes
                  2. It's easier to delete all the spawned pages each time and to re-spawn in order only those that are checked.

                  See attached sample file, it uses this script:
                  Code:
                  function managePages() {
                  // remove all previously spawned pages
                  if (this.numPages > 1) {this.deletePages({nStart: 1, nEnd: this.numPages-1});}
                  // spawn checked page(s)
                  if (this.getField("Additional Company Branch 1").value != "Off") {this.getTemplate("AdditionalCompanyBranch1").spaw n(this.numPages, false, false);}
                  if (this.getField("Additional Company Branch 2").value != "Off") {this.getTemplate("AdditionalCompanyBranch2").spaw n(this.numPages, false, false);}
                  if (this.getField("Additional Company Branch 3").value != "Off") {this.getTemplate("AdditionalCompanyBranch3").spaw n(this.numPages, false, false);}
                  if (this.getField("Additional Contacts 1").value != "Off") {this.getTemplate("Additional Contacts 1").spawn(this.numPages, false, false);}
                  if (this.getField("Additional Contacts 2").value != "Off") {this.getTemplate("Additional Contacts 2").spawn(this.numPages, false, false);}
                  if (this.getField("Additional Contacts 3").value != "Off") {this.getTemplate("Additional Contacts 3").spawn(this.numPages, false, false);}
                  // go back to first page
                  this.pageNum = 0;
                  }
                  Thank you for the review and help on this. I appreciate you taking the time to provide the code, it was very helpful!

                  Comment

                  Working...
                  X