8 Replies Latest reply on Jul 3, 2010 12:58 AM by try67

    Prompt Box Script

    Drith

      What is wrong with this script? I got it to work outside of the document but not in the document.

       

      function disp_prompt()
      {
      var fname=prompt("Keep?","answer")
      var a = this.getField("Field1");
      var D1 = Math.round((Math.random()*5)+1);
      var D2 = Math.round((Math.random()*5)+1);
      var D3 = Math.round((Math.random()*3)+1);
      var D0 = D1+D2;
      var x = 0

       

      if (D0==2) (x=20-D0);
      else if (D0==12) {x=20-(D3+6)}
      else if (D1>=D2) {x=20-D1}
      else if (D1<D2) {x=20-D2}
      if (fname=="yes") {a=x}

        • 1. Re: Prompt Box Script
          gkaiseril MVP & Adobe Community Professional

          It appears you do not have the full script. It ends with an 'if' statement and there is no closer for the function. Have you looked at the JavaScript console?

          • 2. Re: Prompt Box Script
            Drith Level 1

            You mean this } ?

             

            I have that at the end of my script I just forgot to type it here.

            • 3. Re: Prompt Box Script
              gkaiseril MVP & Adobe Community Professional

              Well my crystal ball is pretty foggy in this humidity, so I am unable to see the entire code.

               

              It looks more like Java then JavaScript. Have you looked at Acrobat's JavaScript console for any errors?

               

              I use the Acrobat JS 'app.alert' or 'app.response' method to obtain user input on a form.

              1 person found this helpful
              • 4. Re: Prompt Box Script
                Drith Level 1

                would it be more like this?

                 

                var a = this.getField("Field1");
                var D1 = Math.round((Math.random()*5)+1);
                var D2 = Math.round((Math.random()*5)+1);
                var D3 = Math.round((Math.random()*3)+1);
                var D0 = D1+D2;
                var x = 0

                 

                if (D0==2) (x=20-D0);
                else if (D0==12) {x=20-(D3+6)}
                else if (D1>=D2) {x=20-D1}
                else if (D1<D2) {x=20-D2}

                 

                var P=app.response("Keep"+x+"?","yes or no")
                if (P=="yes") {a=x}
                if (P=="no") {x=0}

                • 5. Re: Prompt Box Script
                  Drith Level 1

                  What I really want to do is have a window pop open when I hit a button generate 6 numbers then ask you which field you want each number to go into.

                   

                  But most of this is beyond my skill. Right now I'm just trying to make it open a box for each value and ask you where you want to put the number.

                  • 6. Re: Prompt Box Script
                    gkaiseril MVP & Adobe Community Professional

                    Have you looked at the references I provided you a link for?

                     

                    The 'app.alert' provides for different repsonse buttons, including a 'Yes' and 'No' button.

                     

                     

                    var a = this.getField("Field1");
                    var D1 = Math.round((Math.random()*5)+1);
                    var D2 = Math.round((Math.random()*5)+1);
                    var D3 = Math.round((Math.random()*3)+1);
                    var D0 = D1+D2;
                    var x = 0

                     

                    if (D0==2) (x=20-D0);
                    else if (D0==12) {x=20-(D3+6)}
                    else if (D1>=D2) {x=20-D1}
                    else if (D1<D2) {x=20-D2}

                     

                    var cResponse = app.alert({cMsg: 'Keep ' + x  + ' ?',
                    nIcon:2,
                    nType: 2,
                    cTitle: 'Keep Roll'
                    })

                    if (cResponse == 4 ) {
                    // yes selected
                    a.value =  x;
                    } else {
                    // no selected
                    x = 0;
                    }

                    1 person found this helpful
                    • 7. Re: Prompt Box Script
                      Drith Level 1

                      I was just told to change the math part of the script and came up with this(see below) it works. But now I have to make a drop down box instead of having the user input the field. How do I make it a drop down box?   Sorry if I'm being fustrating.... and Thanks for the assistance.

                       

                      var a = this.getField("Field1");
                      var b = this.getField("Field2");
                      var c = this.getField("Field3");
                      var d = this.getField("Field4");
                      var e = this.getField("Field5");
                      var f = this.getField("Field6");
                      var D1 = Math.round((Math.random()*5)+1);
                      var D2 = Math.round((Math.random()*5)+1);
                      var D3 = Math.round((Math.random()*5)+1);
                      var D0 = D1+D2+D3;
                      var x = 0;

                       

                      if (D0<=7) {x=7}
                      else if (D0>=7) {x=D0}

                       

                      var P=app.response("Where do you want "+x+": Field1, Field2, Field3, Field4, Field5, Field6","")
                      if (P=="Field1") {a.value=x}
                      else if (P=="Field2") {b.value=x}
                      else if (P=="Field3") {c.value=x}
                      else if (P=="Field4") {d.value=x}
                      else if (P=="Field5") {e.value=x}
                      else if (P=="Field6") {f.value=x}

                      • 8. Re: Prompt Box Script
                        try67 MVP & Adobe Community Professional

                        That can't be done with the app.response function, but can be done using a

                        dialog, which is much more flexible, but also much more complicated.

                        Have a look at the reference of app.execDialog for more info.