Skip navigation
Currently Being Moderated

how to limit field entries to 1 or 3?

Dec 22, 2011 9:01 AM

Tags: #acrobat #javascript #form_fields #custom_field_validation #validation_script

Hi -

 

I need a very simple java script that will limit a field's entries to 1 or 3. I believe this is a custom validation script.

 

I don't know why acrobat requires us to use javascript for something so basic, but apparently they do, so I'd greatly appreciate any help on how to do this.

 

If it's just a matter of putting in a standard shell and then using a GREP expression, can someone tell me how to set it up so I can customize it in the future?

 

Learning javascript has been on my to do list for a while, but if I need to use it for something like this I think I'll have to push it to the top of the list.

 

I've seen other scripts on the forums to do other sorts of field validation but can't tell how much of it I need to include for this.

 

Thanks in advance for the help.

 
Replies
  • George Johnson
    11,676 posts
    Aug 11, 2002
    Currently Being Moderated
    Dec 22, 2011 10:04 AM   in reply to Mayerchak

    Here's a topic from yesterday that discusses something very similar (a or d instead of 1 or 3): http://forums.adobe.com/thread/940007

     

    You should be able to adapt this to suit your needs, but if you get stuck, post again.

     
    |
    Mark as:
  • George Johnson
    11,676 posts
    Aug 11, 2002
    Currently Being Moderated
    Dec 22, 2011 11:03 AM   in reply to Mayerchak

    The code has to be placed in a document-level function and the function then needs to be called from the field's Keystroke event. There is a good reason for this, but explaining it might just confuse things unnecessarily. If you don't know how to create a document-level JavaScript, I can provide directions, but the specifics depend on which version of Acrobat you're using. So let me know and I'll post more info.

     
    |
    Mark as:
  • George Johnson
    11,676 posts
    Aug 11, 2002
    Currently Being Moderated
    Dec 22, 2011 11:05 AM   in reply to George Johnson

    This topic discusses how to add a new document-level function and call it, but the details are specific to to Acrobat 9 (and maybe 8): http://forums.adobe.com/thread/940004

     
    |
    Mark as:
  • George Johnson
    11,676 posts
    Aug 11, 2002
    Currently Being Moderated
    Dec 22, 2011 11:07 AM   in reply to George Johnson

    I was actually thinking of this one: http://forums.adobe.com/message/4095955#4095955

     

    but the other includes other information that should be useful as well.

     
    |
    Mark as:
  • George Johnson
    11,676 posts
    Aug 11, 2002
    Currently Being Moderated
    Dec 22, 2011 12:35 PM   in reply to Mayerchak

    In Acrobat 10, you have to select: Tools > JavaScript > Document JavaScripts

     

    A problem may be that you don't have the JavaScript panel set to show. If so, click the (very) small "Show or Hide Panels" icon/button at the top-right of the Tools panel to select JavaScript.

     

    You would normally be able to place the keystroke script code directly into the editor, but since the code I showed uses some built-in functions, you have to do it the way I described due to what I consider to be a bug in Acrobat.

     

    Also, you're showing the validate tab. It would be possible to validate the entry after the user commits it, and reject any invalid entries, but the keystroke script approach will prevent the user from being able to make invalid entries in the first place. Whether this is the best approach is for you to say. If you want to go with a validate script, the code would necessarily be different than the code for a keystroke script. Post again if this is what you want and I can revise the code to work as a validate script.

     
    |
    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