Skip navigation
Currently Being Moderated

Required Form Fields with JavaScript

Aug 20, 2012 7:03 AM

Hello -

 

I have been working on a PDF form using Acrobat 9 Pro.  The form will not be submitted with a submit button but rather filled out and saved by the user.

 

So, I have been using JavaScript under Actions>On Blur

 

I have been through a few different scripts because initially I could not get the JavaScript that was in the Adobe Development Tips to work on both a PC and a Mac.  Then, someone in these forums was kind enough to help me and it worked.  The only problem is that now if I click inside of a required form field without typing anything and then click inside of another required form field the cursor does not stay in the first required form field that I clicked out of.  It moves to the next required form field.  Is there a way to make the cursor stay in the first required form field until you fill it out?  So in other words you cannot click inside of another form field until you fill out the required one that you clicked into.

 

The correct popup message appears when you leave the first field without filling it out and click into another field but I want the user not to be able to even click into another required field until they fill out the one they clicked into first.

 

Here is the script 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. ")

    }

 

Many thanks! 

 
Replies
  • Currently Being Moderated
    Aug 20, 2012 7:12 AM   in reply to mdwebcat

    Think long and hard about this. Preventing the user from doing anything also will not allow a user to save the form. Also the end user can set Acrobat/Reader to not allow JavaScript and defeat you.

     
    |
    Mark as:
  • George Johnson
    9,208 posts
    Aug 11, 2002
    Currently Being Moderated
    Aug 20, 2012 10:23 AM   in reply to mdwebcat

    Try something like this:

     

    // On Blur script

    if (!event.target.valueAsString) {

        app.alert("This field is required.", 3);

        event.target.setFocus();

    }

     
    |
    Mark as:
  • George Johnson
    9,208 posts
    Aug 11, 2002
    Currently Being Moderated
    Aug 20, 2012 1:05 PM   in reply to mdwebcat

    Did you use the exact script that I posted, or did you place the app.alert line after the setFocus line?

     
    |
    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