These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Format validation based on combo box value?

ecoliguy
Registered: Nov 19 2008
Posts: 19
Answered

I'd like the value of a combo box (which can be one of four values) to force the format of another field to a certain initial alphanumeric string. For example, if the combo box value is "A", then I want the value of field "Batch" to start out as "A3456-789-####", where the #s can be any character, user-entered, but the A3456-789- should stay as a default value that could be changed. If the combo box value is "B", then I need the Batch field to be something like "B12-12YZ12-#######". The two formats are similar only in that they have two hyphens; the number of characters between them are different.

I'm pretty Java-stupid, so if there's a way to do it without, all the better...but I can learn.

I should also probably mention that I'm using Acrobat 8.

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Do you need the text field to enforce the format, or do you just want to pre-populate the text field with those characters when a certain combo box item is selected? By enforce I mean not accept an entry that does not match the specified format.

George
ecoliguy
Registered: Nov 19 2008
Posts: 19
Prepopulate - 95% of the entries will be in tha format, but once in a while, it will need to be something completely different.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
OK, here's some sample code intended to be used as a custom validation script for the combo box:

(function () { // Get the item value that the user selectedvar item = event.value; // Create an object to associate the combo box item with// some text to display in the text boxvar obj = {"A": "A3456-789-","B": "B12-12YZ12-","C": "Text for C","D": "Text for D",// Continue for any other comb box items} // If the item value is present in the object...if (item in obj)  { // Pre-populate the text boxgetField("Text1").value = obj[item]; } else { // Reset the text box resetForm(["Text1"]); } })();

Instead of using the JavaScript object, you use the export value of the combo box items to specify your prepopulation text, but this gives you a bit more flexibility. Replace "Text1" in the code above with the name of your text field.

Thom Parker has some articles on scripting combo boxes here (JavaScript Corner), so read those for some good information.

George
ecoliguy
Registered: Nov 19 2008
Posts: 19
Excellent, George! Plugged that in, made my modifications, and it worked like a charm!