7 Replies Latest reply on Jan 31, 2012 10:17 AM by jl535156

    Adobe form validation with Print button

    jl535156 Level 1

      Hi All,

       

       

      I have an adobe form with field validation (javascript) already set up but I'm trying to add one more feature to the validation.

       

       

      Let me explain my initial validation first:  I have 18 required fields with their tooltip name having an '*' at the end.  Any fields not filled in with this tooltip marker will show up on an alert message when the print button is selected.

      There are two fields called IException and Amount that are required but an End User might have additional IExceptions and corresponding Amounts.  Therefore I have created 5 textboxes for each but only the first IException and Amount are absolutely required (and I use a '*' within their tooltip).  Now if an End User has an additional IExceptions ("IException2") and fills out this field, I need to make it mandatory that "Amount2" would also have to be filled in.

       

      Here is my code: [code]

      function validateFields()
      {
      var flg = 0
      var n = this.numFields
      var fArr = new Array();


      for(var i = 0;i<n;i++)
      {
      var fn = this.getNthFieldName(i);
      var f = this.getField(fn);
      var tt = f.userName

       


      if(tt.indexOf('*')!=-1 && f.value == f.defaultValue)
      {
      flg++;
      fArr[fArr.length] = tt;
      }
      }
      if(flg>0)
      {
      app.alert('There are '+flg+' fields that require a value\n\n'+ fArr,3)
      var IException2 = document.getElementById('IException2').value;
      var Amount2 = document.getElementById('Amount2').value;
      if ((IException2.length >0) && (Amount2.length == 0))
      {
      app.alert('Amount is missing')
      }
      else
      {
      document.ExceptionForm1.print();
      }
      }
      }

      validateFields();

       

      [/code]

       

       

      Currently when one of the require fields is NOT filled in, i receive my first alert message.  If all required fields are filled in my print button doesn't work.  Also if all required fields are filled in and IException2 is also filled in but Amount2 is not, I don't receive my second Alert message.  So my code works up to the "Var IException2 = document....." and I don't know what the issue is.

       

      Thank you for your help in advance. 

        • 1. Re: Adobe form validation with Print button
          try67 MVP & Adobe Community Professional

          You're using syntax that is used in LC forms (getElementById). If this is

          not an LC form, then your code is incorrect.

          If it is, post your question in the LC Designer forum.

          1 person found this helpful
          • 2. Re: Adobe form validation with Print button
            jl535156 Level 1

            No this isn't Life Cycle.

             

            Just a normal Adobe Form (Adobe 9 Pro) with textboxes to be filled in and a print button at the bottom for end users to print and mail/email/fax to our office.

             

            What kind of code would I be looking for??

             


            PS Thank you for the quick response

            • 3. Re: Adobe form validation with Print button
              try67 MVP & Adobe Community Professional

              document.getElementById() doesn't exist (I actually think it's from a

              web-broweser JavaScript).

              You need to use this.getField() to retrieve a field.

               

              Also, this code is not valid:

              document.ExceptionForm1.print();

              To print the file you can use:

              this.print();

              • 4. Re: Adobe form validation with Print button
                jl535156 Level 1

                I don't have it right but this is what I have:

                if(flg>0)
                {
                app.alert('There are '+flg+' fields that require a value\n\n'+ fArr,3)
                }
                var a = this.getField('IException2');
                var b= this.getField('Amount2');
                if ((a.length >0) && (b.length == 0))
                {
                app.alert('Amount is missing')
                }
                else
                {
                this.print();

                }
                }

                 

                 

                I figured that part of the code was wrong.  Can you assist a little bit more.  When I click print, it will give me an error of whatever fields I didn't fill in but then the print screen pops up anyways.  There is also no mention of Amount 2 needing to be filled in...My If and Else might be the problem...I'm familiar with coding but not great and trying to do this for my boss..

                • 5. Re: Adobe form validation with Print button
                  try67 MVP & Adobe Community Professional

                  a and b should be the value of the fields, not just the fields themselves.

                  So you can use either this:

                  var a = this.getField('IException2').value;

                  var b= this.getField('Amount2').value;

                   

                  Or this:

                   

                  if ((a.value.length >0) && (b.value.length == 0))

                  • 6. Re: Adobe form validation with Print button
                    jl535156 Level 1

                    That did it...thank you soo much!!!!

                    • 7. Re: Adobe form validation with Print button
                      jl535156 Level 1

                      One more question,  since I have 4 of these...I'm having trouble getting the button to do exactly what its suppose to based on what's filled in because i think i have my '{ }' messed up and or IF/ELSE statement is wrong...can you please take a look..

                      function validateFields()
                      {
                      var flg = 0
                      var n = this.numFields
                      var fArr = new Array();


                      for(var i = 0;i<n;i++)
                      {
                      var fn = this.getNthFieldName(i);
                      var f = this.getField(fn);
                      var tt = f.userName

                      if(tt.indexOf('*')!=-1 && f.value == f.defaultValue)
                      {
                      flg++;
                      fArr[fArr.length] = tt;
                      }
                      }

                      if(flg>0)
                      {{
                      app.alert('There are '+flg+' fields that require a value\n\n'+ fArr,3)
                      }

                      var a = this.getField('IException2').value;
                      var b= this.getField('Amount2').value;
                      if ((a.length >0) && (b.length == 0))
                      {
                      app.alert('Since IException 2 is filled in, Amount 2 is also required')
                      }


                      var c = this.getField('IException3').value;
                      var d= this.getField('Amount3').value;
                      if ((c.length >0) && (d.length == 0))
                      {
                      app.alert('Since IException 3 is filled in, Amount 3 is also required')
                      }

                      var e = this.getField('IException4').value;
                      var f= this.getField('Amount4').value;
                      if ((e.length >0) && (f.length == 0))
                      {
                      app.alert('Since IException 4 is filled in, Amount 4 is also required')
                      }

                      var g = this.getField('IException5').value;
                      var h= this.getField('Amount5').value;
                      if ((g.length >0) && (h.length == 0))
                      {
                      app.alert('Since IException 5 is filled in, Amount 5 is also required')
                      }
                      }
                      else
                      {
                      this.print();
                      }
                      }


                      validateFields();