3 Replies Latest reply on Jun 3, 2009 12:59 PM by gkaiseril

    If/Then JavaScript

    pohara

      Hi all,

       

      I am working on a form that automatically fills itself out based on what the user selects using a dropdown box. I am encountering difficulties as, while I am proficient in Excel lingo, I know nothing about Java. I currently have a dropdown box where the user can select one of 4 choices. Based on that selection, I need another part of the form to fill in automatically. If anyone could assist me with this problem I would greatly appreciate it!

       

      I would like the script to accomplish the following:

       

      If the dropdown item selected reads "All Equity", I need the value to be 99.

      If it reads "75-25", I need the value to be 75.

      If it reads "50-50", I need the value to be 50.

      If it reads "25-75", I need the value to be 25.

       

      The dropdown menu is named "Portfolio Allocation" and the target/output blank is named "Equity Allocation".

       

      Any help/tips would be great! Thanks!

        • 1. Re: If/Then JavaScript
          DimitriM Level 3

          Hi pohara,

           

          Here are some tutorials from www.acrobatusers.com on how to program combo boxes and change fields based on a selection in a combo box-

          http://www.acrobatusers.com/tutorials/2006/change_another_field

          http://www.acrobatusers.com/tutorials/2007/js_list_combo_livecycle

           

          First one is for AcroForms only, the second includes both AcroForm and LiveCycle Designer PDFs.  Be sure to check out the downloadable sample files- you can examine the code used.

           

          If you want to learn more about Acrobat JavaScript you may be interested in www.pdfscripting.com , the best on-line resource availble for learning Acrobat and PDF scripting.

           

          Hope this helps,

           

          Dimitri

          WindJack Solutions

          www.windjack.com

          www.pdfscripting.com

          1 person found this helpful
          • 2. Re: If/Then JavaScript
            HarrisFR

            I saw the sample forms but they seem geared toward ES, what if you have a earlier version?  I'm using 7.0, any samples available?

            • 3. Re: If/Then JavaScript
              gkaiseril MVP & Adobe Community Professional

              Since Arobat 6.0, the Windows version of Acorbat has had 2 programs that can create forms, Acrobat and LiveCycle Designer. Both programs can use JavaScript but the exact syntax can is different for field access.

               

              Because of your field's nane it appears you are using Acorbat's AcroForms.

               

              // get the value of field 'Portfolio Allocation'

              var sResult = this.getField('Portfolio Allocation').value;

              switch(sResult) {

              case 'All Equity':

              event.value = 99;

              break;

               

              case '75-25':

              event.value = 75;

              break;

               

              case '50-50':

              event.value = 50;

              break;

               

              case '25-75':

              event.value = 25;

              break;

               

              default:

              // all other answers

              // clear field or other action

              event.value = '';

              break;

              }

               

              // or

               

              // clear field

              event.value = '';

              // get the value of field 'Portfolio Allocation'

              var sResult = this.getField('Portfolio Allocation').value

              if(sResult == 'All Equity')

              event.valaue = 99;

               

              if(sResult == '75-25')

              event.value = 75;

               

              if(sReslult == "50-50")

              event.value = 50;

               

              if(sResult == '25-75')

              event.value = 25;

              1 person found this helpful