Skip navigation
Currently Being Moderated

Required Fields and JavaScript Issue

Aug 16, 2012 8:18 AM

Hello,

 

I have created a form with required fields.  The PDF will not be "submitted" with a Submit button.  However, we still want it to be fillable and have some required fields.  I pulled the JavaScript below from The Adobe Acrobat Developer Tips and it works great on my Mac.  However, when I test on the Windows side it freezes and crashes Adober Reader X.

 

I used Acrobat Pro 9 on my Mac side to create the form.  I use the same versions of Acrobat Reader X on the Windows side and Mac side.

 

Here is the JavaScript I am using.

 

f = getField(event.target.name)

if (f.value.length == 0)

    {
    f.setFocus()
        

    //Optional Message - Comment out the next line to remove
        

    app.alert("This field is required. Please enter a value.")
         

    }

 

 

I removed the JavaScript action and tested again on the Windows side and it opened fine BUT of course the required function is not there without the JavaScript.  So, it seems as though the JavaScript is causing a weird compatability issue? I'm just not sure what the solution is.

 

Any guidance is greatly appreciated. 

 
Replies
  • Currently Being Moderated
    Aug 16, 2012 8:26 AM   in reply to mdwebcat

    Where are you putting your code? Is it in a field event, or document event?

     

    Also,

    f = getField(event.target.name)

    can be shortened to

    f = event.target

     

     

    and you can shorten it even further if you just need the value from

    f = getField(event.target.name)

    if (f.value.length == 0)

     

    to one of the following (depending on which event you are using for your code

    if (event.value.length == 0)

    if (event.target.value.length == 0)

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 8:48 AM   in reply to mdwebcat

    Which action? I'm assuming the 'onBlur' event


    Shortening the code won't change how it runs. The event.target is the field itself, so you don't need to get the name to access the field, but either way should produce the same results (unless there was an issue on the PC, but I doubt that)

     

    fwiw, your code works fine on my PC in the  OnBlur event of a field.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 16, 2012 9:43 AM   in reply to mdwebcat

    I;ll see if I can test it in Reader, perhaps there's an issue there.

     

    Does it work if you comment out the 'setFocus' line?

     

    f = getField(event.target.name)

    if (f.value.length == 0)

        {
   

         // f.setFocus()
        

        //Optional Message - Comment out the next line to remove
        

        app.alert("This field is required. Please enter a value.")
         

        }

     

    Or if you comment out the alert line?

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 22, 2012 11:10 AM   in reply to mdwebcat

    If you put the setfocus after the appalert line, it returns the focus to the field without looping.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points