11 Replies Latest reply on Mar 23, 2016 9:24 AM by kmc27

    Need Script to Continue After Clicking OK on Alert Box

    kmc27 Level 1

      My form has multiple required fields. In order to ensure the form has been filled out completely, the submit button on the form has a javascript action on it to check the contents of the required fields, and if necessary, return the user to that part of the form to enter the required information.

       

      Just before the form is mailed, I am checking for a value of "Vendor_Guidelines" in field 18. If that field's value is "Vendor_Guidelines", I would like to pop up an alert reminding the user to include the guidelines when submitting their request. They should be able to click "OK" on the alert, and continue with submitting their form.

       

      Below is the expert of the script on the submit button. Once the alert displays, I really don't really need to set focus back to f18, I just need the user to be able to click OK and allow the script to continue so the form can be submitted.

       

      Thanks in advance for any ideas on this.

       

       

       

       

                    else if (f18.value == "Vendor_Guidelines")

        {

        app.alert ('You checked the Vendor/Buyer Guidelines checkbox on page one of this form. Attach the guidelines to this request email.');

        f18.setFocus();

        }

        else

        {

              // Email PDF.

              var m = this.getField("ad_desc");

              var mysubject = m.value + " - Request Form Submission";

              this.mailDoc(true, "requestforms@ducjvh.com", "", "", mysubject);

        }

      }

        • 1. Re: Need Script to Continue After Clicking OK on Alert Box
          try67 MVP & Adobe Community Professional

          The use this code:

           

          // original code
          else if (f18.value == "Vendor_Guidelines") {
            app.alert ('You checked the Vendor/Buyer Guidelines checkbox on page one of this form. Attach the guidelines to this request email.');
          }
          
          // Email PDF.
          var m = this.getField("ad_desc");
          var mysubject = m.value + " - Request Form Submission";
          this.mailDoc(true, "requestforms@ducjvh.com", "", "", mysubject);
          
          • 2. Re: Need Script to Continue After Clicking OK on Alert Box
            kmc27 Level 1

            Thanks for the help.

             

            When I make the edits, the form behaves differently:

             

            Prior to the edit, when the "Submit" button was clicked, the form would call out any missing required fields, and not proceed with emailing the form until they were filled out;. Once all required fields were completed, the submit button would open a new email message and attach the form using the default email client.

             

            After making the edit two things changed:

             

            1. An alert box appears when a required field had not been completed, but it then the script proceeds to mail the form even though some required data is missing

            2. The form no longer automatically opens an email using the default email client.  Instead A "Send Email" dialogue box opens asking "How would you like to send the email?. It shows two radio button choices: "Default email application (Microsoft Outlook)" or "Use Webmail"

             

            I made the edits several times to be sure I wasn't missing anything. Do you have any suggestions for me?

            • 3. Re: Need Script to Continue After Clicking OK on Alert Box
              try67 MVP & Adobe Community Professional

              I was afraid of something like that... That's what happens when you only provide partial code and don't explain exactly how it's working and how it should work.

               

              So you want the file to be submitted when the alert is shown, but not in other circumstances? If so, then move the code that's outside the curly brackets inside of them.

               

              You'll notice I didn't change anything about how the file is being submitted, so it should work exactly the same as before, unless you changed something else.

              • 4. Re: Need Script to Continue After Clicking OK on Alert Box
                kmc27 Level 1

                I went back and did a copy and paste of the edit you provided just to make sure I didn't make any text edits. When I save and close the script in the text editor, Acrobat gives me this message:

                 

                "JavaScript error at line 152: SyntaxError: missing } in compound statement

                151:. Fix it?"

                 

                Here is what the script looks like after editing. There is nothing at line 152 or line 151. Any ideas on this?

                 

                Screen Shot 2016-03-18 at 5.38.58 PM.png

                • 5. Re: Need Script to Continue After Clicking OK on Alert Box
                  kmc27 Level 1

                  OK, here is the entire submit button script (after making the edit)

                   

                   

                  // If Reader 6 or below is being used, display message telling user that "Email" and "Save Data" buttons don't work.

                  if (app.viewerType == "Reader" && app.viewerVersion < 7)

                  {

                      var cMsg1 = "This form cannot be submitted with your version of Acrobat Reader.\nYou must use Acrobat Reader version 7 or higher.";

                      app.alert(cMsg1, 1);

                  }

                  else

                  {

                    f1 = this.getField("ad_no");

                    f2 = this.getField("ad_desc");

                    f3 = this.getField("cbo_spon ad dmm");

                    f4 = this.getField("cbo_spon ad dept");

                    f5 = this.getField("txt_vendor contact")

                      f6 = this.getField("txt_buyer");

                    f7 = this.getField("start_date");

                      f8 = this.getField("end_date"),

                    f9 = this.getField("flight start date");

                    f10 = this.getField("flight end date");

                    f11 = this.getField("chk_60 length");

                    f12 = this.getField("chk_30 length");

                    f13 = this.getField("chk_15 length");

                    f14 = this.getField("chk_10 length");

                    f15 = this.getField("rdo_rating points");

                    f16 = this.getField("rdo_rating points");

                    f17 = this.getField("txt_rating points amount");

                    f18 = this.getField("rdo_ad guidelines");

                      f19 = this.getField("rdo_ad guidelines");

                    f20 = this.getField("rdo_media type");

                      f21 = this.getField("lboCPS_TV");

                    f22 = this.getField("lboCPS_RADIO");

                    f23 = this.getField("lboBOS_TV");

                    f24 = this.getField("lboBOS_RADIO");

                    f25 = this.getField("lboPAB_TV");

                      f26 = this.getField("lboPAB_RADIO");

                    f27 = this.getField("lboHRB_TV");

                    f28 = this.getField("lboHRB_RADIO");

                    f29 = this.getField("lboYNK_TV");

                      f30 = this.getField("lboYNK_RADIO");

                      f31 = this.getField("lboBT_TV");

                    f32 = this.getField("lboBT_RADIO");

                    f33 = this.getField("lboEB_TV");

                    f34 = this.getField("lboEB_RADIO");

                    f35 = this.getField("lboHRBYNK_TV");

                    f36 = this.getField("lboHRBYNK_RADIO");

                    f37 = this.getField("lboPABEB_TV");

                      f38 = this.getField("lboPABEB_RADIO");

                    f39 = this.getField("lboBOSEB_TV");

                    f40 = this.getField("req_by");

                        if (f1.value == "Type the ad number. If none, type \"TBD\".")

                    {

                    app.alert ('Please enter an ad number or type TBD.');

                                      f1.setFocus();

                    }

                    else if (f2.value == "")

                    {

                    app.alert ('Please enter an Ad Description.');

                    f2.setFocus();

                    }

                    else if (f3.value == "Select a DMM" && f4.value == "Select a Department")

                    {

                    app.alert ('Please select an Ad Sponsor.');

                    f3.setFocus();

                    }

                    else if (f5.value == "Type vendor contact name and phone/email here.")

                    {

                    app.alert ('Please enter the name and phone number/email address of the product vendor contact.');

                    f5.setFocus();

                    }

                                  else if (f6.value == "Type Buyer's name and phone number here.")

                    {

                    app.alert ('Please enter the name of the Buyer\'s name and phone number.');

                    f6.setFocus();

                    }

                                 else if (f7.value == "")

                    {

                    app.alert ('Please enter a start date for your ads.');

                    f7.setFocus();

                    }

                                 else if (f8.value == "")

                    {

                    app.alert ('Please enter an end date for your ads.');

                    f8.setFocus();

                    }

                                 else if (f9.value == "")

                    {

                    app.alert ('Please enter the flight start date.');

                    f9.setFocus();

                    }

                                 else if (f10.value == "")

                    {

                    app.alert ('Please enter the flight end date.');

                    f10.setFocus();

                    }

                   

                                 else if (f11.value == "Off" && f12.value == "Off" && f13.value == "Off"  && f14.value == "Off")

                    {

                    app.alert ('Please check the length of the spot - check all lengths that apply.');

                    f11.setFocus();

                    }

                   

                   

                    else if (f15.value == "Off" && f16.value == "Off")

                    {

                    app.alert ('Please indicate either "Gross Rating Points" or "Targeted Rating Rpoints".');

                    f15.setFocus();

                    }

                                 else if (f17.value == "")

                    {

                    app.alert ('Enter a value for the amount of Rating Points.');

                    f17.setFocus();

                    }

                    else if (f18.value == "Off" && f19.value == "Off")

                    {

                    app.alert ('Please check either "Vendor Guidelines" or "Corporate Guidelines".');

                    f18.setFocus();

                    }

                               else if (f20.value == "Off")

                    {

                    app.alert ('Please indicate whether this is a radio or TV ad request');

                    f20.setFocus();

                    }

                               else if (f21.value == "Choose" && f22.value == "Choose" && f23.value == "Choose" && f24.value == "Choose" &&

                   

                   

                  f25.value == "Choose" && f26.value == "Choose" && f27.value == "Choose" && f28.value == "Choose" && f29.value ==

                   

                   

                  "Choose" && f30.value == "Choose" && f31.value == "Choose" && f32.value == "Choose" && f33.value == "Choose" && f34.value == "Choose" &&

                   

                   

                  f35.value == "Choose" && f36.value == "Choose" && f37.value == "Choose" && f38.value == "Choose" && f39.value ==

                   

                   

                  "Choose")

                    {

                    app.alert ('Please go to the "Market Specifics" section and indicate where your ad(s) should run.');

                    f21.setFocus();

                    }

                                else if (f40.value == "")

                    {

                      app.alert ('The "Requested by" line cannot be blank. Please type the name of the person requesting this ad.');

                    f40.setFocus();

                    }

                    else if (f18.value == "Vendor_Guidelines") { 

                    app.alert ('You checked the Vendor/Buyer Guidelines checkbox on page one of this form. Attach the guidelines to this request email.'); 

                    } 

                   

                    // Email PDF. 

                    var m = this.getField("ad_desc"); 

                    var mysubject = m.value + " - Request Form Submission"; 

                    this.mailDoc(true, "requestforms@ducjvh.com", "", "", mysubject); 

                  • 6. Re: Need Script to Continue After Clicking OK on Alert Box
                    try67 MVP & Adobe Community Professional

                    But you still didn't say when the file should be submitted...

                     

                    I'm not sure where the problem is but there are 19 instances of "{" in this code but only 18 of "}"...

                    • 7. Re: Need Script to Continue After Clicking OK on Alert Box
                      kmc27 Level 1

                      Thanks for taking a look at this. Once the check of whether f18 has a value of "Vendor_Guidelines", the script should go on to submit. I just want the alert box to function as a reminder to the submitter that if they had selected Vendor_Guidelines for f18, they should remember to include those guidelines with their request. I suppose I could do a static text box with this message next to the submit button, but I thought if the reminder was driven by an alert box that popped up on-screen, it would be a more effective reminder. Maybe for this purpose, that is the incorrect use of this script.


                      The mismatch in number of braces is due to my editing - some previously required fields no longer need to be required.

                      • 8. Re: Need Script to Continue After Clicking OK on Alert Box
                        try67 MVP & Adobe Community Professional

                        But what about all the other conditions before it? Should it also submit the file any of them is true?

                        • 9. Re: Need Script to Continue After Clicking OK on Alert Box
                          kmc27 Level 1

                          No, it should not submit if any of the other conditions are true. I think there are three scenarios as to how this form could be filled out by the users: As I wrote them out below, I began to think what I am trying to accomplish is not realistic:

                           

                          1. User is missing data in a required field. They have also checked the "Vendor/Buyer Guidelines checkbox

                          Action when clicking "Submit" Alert displays telling them data is missing, they click "OK" and add the missing data. User then clicks "Submit" button again. All required fields have been completed,  Alert box displays reminding them to include the guidelines with their request, They click OK and the script kicks off the this.mailDoc action

                           

                          2. User is NOT missing data in a required field. They have also checked the "Vendor/Buyer Guidelines checkbox

                          Action when clicking "Submit"  User then clicks "Submit" button, alert box displays reminding them to include the guidelines with their request, They click OK and the script kicks off the this.mailDoc action

                           

                          3. User is NOT missing data in a required field. They have NOT checked the "Vendor/Buyer Guidelines checkbox

                          Action when clicking "Submit" Script kicks off the this.mailDoc action

                           

                          Maybe my best option for an reminder is to put an action on the "Vendor/Buyer Guidelines" checkbox so that a hidden text box appears telling them to remember to submit the guidelines.

                           


                          .

                          • 10. Re: Need Script to Continue After Clicking OK on Alert Box
                            try67 MVP & Adobe Community Professional

                            OK, generally speaking, instead of duplicating the submit code you can declare a variable at the start of the code, set it as false, and then set it as true in all of the conditions where you want the file to be submitted finally. Then at the end of the code you submit the form if that variable is true.

                             

                            So something like this:

                             

                            var submit = false;

                            if (condition1) {

                                 submit = true;
                            } else if (condition2) {

                                 submit = true;

                            } else if (condition3) {

                                 // ...

                            } else if (condition4) {

                                 // ...

                            } else {

                                 // ...
                            }

                             

                            if (submit) {

                               var m = this.getField("ad_desc");

                                var mysubject = m.value + " - Request Form Submission";

                                this.mailDoc(true, "requestforms@ducjvh.com", "", "", mysubject); 

                            }

                             

                            So in this scenario the file will be submitted only if conditions 1 or 2 were true. Hope that makes sense...

                            • 11. Re: Need Script to Continue After Clicking OK on Alert Box
                              kmc27 Level 1

                              Thanks. I think I over complicated this. I would like to make it work with an alert box, but to get the form to the user, I created a hidden text box with the message about submitting the necessary guidelines. I placed the hidden box adjacent to the "Submit" button so it cannot be easily missed. If the user puts a mark in the "Vendor/Buyer Guidelines" checkbox, it reveals the hidden text box and thus reminding them(I hope!) to submit the needed guidelines.

                               

                              I was not sure how to implement your suggestion within the script, and also to get the custom alert message. I will try it again this week, because I think the alert box might be more effective vs un-hiding a text box.