5 Replies Latest reply on Mar 15, 2012 5:13 AM by camilo umaña

    How to repair a very good script?

    camilo umaña Level 1

      I found in the web this script, wrote by Ted Padova in 101 tips (below)

       

      The problem is that the second part of the script shows a error in the last line

       

      15. break; // exit loop prematurely

       

      missing { in compound statement

       

      I tried to fix it checking the syntax for similar loop actions but could not find it.

      Any help with this could clear this thread.

       

      Checking for Empty Fields

      Before a document is submitted, you might want to have the form

      checked to be certain that all fields have been filled in. The script to

      perform such a function has two parts. The first part is a function

      added as a document level JavaScript. The second part is the script

      that executes when the Submit a Form button is clicked.

      Add the following function as a Document Level JavaScript and

      name the function aField:

      Choose Advanced | Document Processing | Document

      JavaScripts.

      Type aField in the Script Name text box and click Add.

      Type the following code in the JavaScript Editor.

      1. function checkField(aField)

      2. {

      3. if (aField.value == "") // empty field

      4. {

      5. var msg = "No fields can be left empty.";

      6. app.alert(msg);

      7. return 0;

      8. }

      9. } // end of function

      Click Close in the JavaScript Functions dialog box.

       

       

      On a submit button, add the following script:

      1. // the procedure begins here

      2. var okToSubmit = true;

      3. // loop over all fields:

      4. for (var j = 0; j < this.numFields; j++)

      5. {

      6. var fieldname =

      7. this.getNthFieldName(j);

      8. var theField = this.getField(fieldname);

      9. if (theField.type != 'text')

      10. continue; // get past the button fields

      11. var valid = checkField( theField );

      12. if (!valid) // valid == 0? Halt!

      13. {

      14. okToSubmit = false; // set flag

      15. break; // exit loop prematurely

       

      The above routine checks all text fields to be certain some data

      exist in the fields. If a field is left empty, the app.alert

        • 1. Re: How to repair a very good script?
          camilo umaña Level 1

          Mr Ariel Walden wrote:  (he only scripts for Indesign)

          Try adding two }} at the end of the script. They seem to be missing.

           

           

          Perhaps, that is the reason many people don't script —like myself, I suppose — as this kind of very difficult mysteries never get solved.

           

          In the same line, that could have helped, another script never got solved for the same reason:

           

          http://forums.adobe.com/thread/869330

           

          Dead donkey, dead load.

          • 2. Re: How to repair a very good script?
            George_Johnson MVP & Adobe Community Professional

            But you do script, and you're learning, which is what you need to do. As you learn the language more, you'll have fewer problems like this, or at least you'll be able to identify and fix them easier. A lot of people try to script without learning the language, which only makes things more difficult.

            • 3. Re: How to repair a very good script?
              camilo umaña Level 1

              Thank you.

               

              What about this?

              Although is not working, in theory it seems a solution?

               

              How to re-write line 3?

               

              As a Documenl level script:

              1. function checkField(aField)

              2. {

              3. if (aField.value == "") // empty field

              4. {

              5. var msg = "No fields can be left empty.";

              6. app.alert(msg);

              7. return 0;

              8. }

              9. } // end of function

               

               

              As a Mouse Script generic for a trigger button (next/previous page/ print form...):

               

                             checkFieldsOnPage(pageNum);

               

               

              PD I am observing that some threads here are from designers who want to improve forms, but no so far as learning a lot of Java. The Indesign scripting forum is different as only very special situations are posted: the software is very strong and very well documented. In Acrobat all has to be scripted and a practical use of functions are a nightmare for designers. For example: validating fields is a must for today. But all the threads I read these days are unconcluded, not really clear. Validating field for something outside the Java circle is impossible. Perhaps something that alters the scenery is that scripted solutions are usually sold. It is a business behind it, something that does not happen frequently in Indesign.

               

               


              • 4. Re: How to repair a very good script?
                Bernd Alheit Adobe Community Professional & MVP

                Note:

                 

                Acrobat uses Javascript not Java.

                • 5. Re: How to repair a very good script?
                  camilo umaña Level 1

                  Thank you.

                  Javascript!

                   

                  Anything else?