/ Id-Extras Forum / FormMaker Pro – Combo Box Export Values / Reply To: FormMaker Pro – Combo Box Export Values

#6290
~~Ariel~~
Participant

    Hi Ryan,
    Excellent question!
    You’re right that this is an InDesign omission. But then, when it comes to forms, InDesign is very weak, which is exactly what FormMaker is there to help with.
    As you have found, there is no direct way of adding values to combo box items even with FormMaker.
    But there’s an excellent workaround which I will describe, which I think you’ll find is actually almost as easy.
    The trick is to use FormMaker to add a “document” Javascript to the form. Document scripts are run whenever the form is opened in Acrobat Reader.
    But even better for our purposes, document Javascripts are run when you run the FormMaker command on the form in Acrobat. Which is something you have to do anyway.
    So, what we’re going to do is to write a document Javascript that will populate ALL your combo boxes with both item names and their corresponding values. This is very easy to do, and I’ll give an example further down.
    Once you’ve added this document script in InDesign, it will be there forever (for that document) so you need only do this once (of course, you can modify it as needed if changes need to be made to the form.)
    You will then export to interactive PDF as usual and run the FormMaker command as usual. Doing so will invoke the document Javascript, and you’ll find that all the combo boxes are populated as needed.
    Now you can save the PDF and distribute it to end users.
    In fact, before saving the PDF, you might want to take one extra step – to delete the (now unneeded) document Javascript from the PDF. There’s no reason to distribute the PDF with that doc script included, since we are the ones who needed it, not the end user. (The combo boxes are already populated with items and their values, and that’s all the doc script is needed for.)

    Here’s a sample Javascript that you can tweak to add items and values to combo boxes. You might even find that it’s easier to add the items this way than to use InDesign’s slightly clunky user interface for adding one item at a time.
    The script assumes that you have an InDesign document open with 2 combo boxes in it, called “Combo Box 1” and “Combo Box 2”.

    Code:

    c = this.getField("Combo Box 1");
    c.setItems([["California", "CA"], ["Massachusetts", "MA"], ["Arizona", "AZ"]]);
    c = this.getField("Combo Box 2");
    c.setItems([["Apples", "100"], ["Pears", "200"], ["Oranges", "300"]]);

    The basic idea should be clear: We’re using the “setItems” command to add items and their values to each combo box. The items and their values are provided as a set of small 2-element arrays inside one larger array.

    I’m also attaching a PDF that shows the end result. This PDF includes the document Javascript, although, as mentioned, it makes more sense to delete it from the PDF before saving and distributing it.

    Hope that helps! If anything is unclear or if you have any other questions, post back.

    Thanks,
    Ariel