4 Replies Latest reply on Feb 12, 2012 3:03 PM by nabnub

    Solicit help for writing a scipts

    nabnub

      Hi,

       

       

      I made a form (with Adobe Acrobat Reader Pro 9), I would like to ameliorate the way to display the inputted data

       

      I made a screen capture which summarise the modification wanted,

       

       

      in (1) I would like to be able to select the short date and to diplay it like this: (dd/mm/yyyy)

       

      in (2) I've tried a script but the field in the result column is always equal to 1 when nothing have been input in C1

       

       

      var a = this.getField("Resultat");

      h.value = 0;

      var b = this.getField("ValeurB");

      var c = this.getField("ValeurA");

      a.value = (b.value - c.value) + 1;

       

      in (3) I have to count always (with my fingers lol) the time spent between the date started and date finished, is it possible to write a script?

       

       

      ( I've never used Javascript before, it's my first experience)

       

       

      thank you in advance for your help.

       

       

       

       

       

       

      english picture.jpg

        • 1. Re: Solicit help for writing a scipts
          nabnub Level 1

          sorry for the big mistake in the title, it's "scripts" and without "a"

          • 2. Re: Solicit help for writing a scipts
            George_Johnson MVP & Adobe Community Professional

            For the #2 calculation, yuo can use the following custom Calculate script for the "Resultat" field:

             

             

            // Custom Calculate script
            (function () {
            
                var b = getField("ValeurB").valueAsString;
                var c = getField("ValeurA").valueAsString;
            
                // Only perform the calculation if both fields have an entry
                if (b && c) {
            
                    // Convert the string values to numbers
                    b = +b;
                    c = +c;
            
                    // Set this field value
                    event.value = b - c + 1;
            
                } else {
                    event.value = 0;
                }
            
            })();
            
            • 3. Re: Solicit help for writing a scipts
              George_Johnson MVP & Adobe Community Professional

              For the date difference calculation, you can do something like the following for the custom Calculate script of the field that shows the difference:

               

               

              (function () {
              
                  // Get the date field values
                  var s1 = getField("d1").valueAsString;
                  var s2 = getField("d2").valueAsString;
              
                  // If both fields have an entry...
                  if (s1 && s2) {
              
                      // Convert the date strings to date objects
                      var d1 = util.scand("dd/mm/yyyy", s1);
                      var d2 = util.scand("dd/mm/yyyy", s2);
              
                      // Calculate the difference in days
                      var diff = Math.floor((d2 - d1) / 864e5);
              
                      // Set this field to the difference
                      event.value = diff;
              
                  } else {
                      // Clear this field of both dates are not entered
                      event.value = "";
                  }
              
              })();
              

               

              Where "d1" and "d2" are the names of your two date fields. This assumes you have a single field for each date formatted like dd/mm/yyyy. If you're using a separate drop down for the day, month, and year, you'd have to build the date string from the individual field values, but the rest of the script would be the same.

              1 person found this helpful
              • 4. Re: Solicit help for writing a scipts
                nabnub Level 1

                Thanks a lot

                 

                 

                exactly what I was looking for and I realise that I don't really need the (1), it's just making things more difficult for nothing.