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

JS solution brain teaser

digitalwiz
Registered: Mar 9 2011
Posts: 20

Hi everyone,
 
I'm trying to develop a form that uses a combo box at the top and form fields within the document. The action should be that when item 1 is chosen in the combo box a specific item in the form field should appear.
 
The Combo box and form fields will have multiple options. CHoice 1 in combo = choice 1 in text, choice 2 in combo = choice 2.
 
Ive spent 4 hours reviewing this site so far with only small pieces of the answer.
 
What nobody seems to indicate in thier similar solutions is.
 
1) where do you put the JS keystroke? the combo box or the text field?
2) in the combo box I add a 1 number export value per item, so item "test" will have an export value of 1, Test2 will have an export value to 2 and so forth. Is this correct?
 
If i could just understand how the text boxes are linked to the combo box export value i would have a better understanding of how to do this.
 
thanks you for any assistance you can provide.

thanks

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Do you want the export value of the combo box item that is selected to appear in the text field (e.g., 1), or do you want the "face value" (e.g., "test") to appear?

To set the Keystroke script in a combo box, select a Format type of Custom and you'll see where you can enter the script.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Are you using Acrobat or LiveCycle Designer to create your form?

Thom Parker's example in the tutorials use data objects with multi part elements. Each element has a high level name that corresponds to the value of a drop down box item, and under that high level element are elements that have a value that is an array whose elements are values for the options of the next drop down box.

The exact way to code the form is completely dependent upon which program you are using to create your form.

You can down load the examples and use the appropriate program to open the form and look at how each field is setup.

This is programing and it is rather advanced for someone that has very little experience. Working with these scripts requires some experience in programing and debugging programs. The samples are rather simple and do not fully explain how items are named and how to deal with spaces in the element names, so unless one understands the naming conventions and syntax of a computer language or script it can be hard to modify the scripts and understand why they are not working after they are changed.

It is possible to write a lot of code that uses the 'if' or 'switch' statement to control the changing of the downstream drop down box, but the code has far more statements that need to be coded and can be even harder to sort out. This is especially true if one uses the nested if statement.

You might try coding some simpler forms and learn how to program in JavaScript with simpler projects and work up to the more complex programing tasks.

George Kaiser

Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi digitalwiz,

Since you are trying to complete scripting tasks that are not that easy for a true beginner, you may be interested in some training. Visit www.pdfscripting.com , you may find it well worth the membership fee if you are going to be developing more PDF forms.

Also, as gkasieril mentioned there are 70 or more tutorials on a wide variety of scripting topics for both Acrobat and LiveCycle Designer PDF forms here at AUC in the Learning Center. Many of those tutorials include download files so you can examine the scripts. You may also want to spend some time checking out the sample files in the Forms Gallery here- they will give you lots of ideas of what can be done with PDF forms.

Hope this helps,

Dimitri
www.pdfscripting.com
www.windjack.com

digitalwiz
Registered: Mar 9 2011
Posts: 20
Thanks all of you,

I am using just adobe acrobat pro 9.4.2.

thanks

digitalwiz
Registered: Mar 9 2011
Posts: 20
George_Johnson wrote:
Do you want the export value of the combo box item that is selected to appear in the text field (e.g., 1), or do you want the "face value" (e.g., "test") to appear?To set the Keystroke script in a combo box, select a Format type of Custom and you'll see where you can enter the script.
Ideally Gorge, I would like to be able to select and item in the combo box and have a number of text fields change to different text sentences based on the item chosen from the combo box.

thanks

digitalwiz
Registered: Mar 9 2011
Posts: 20
Dimitri wrote:
Hi digitalwiz,Since you are trying to complete scripting tasks that are not that easy for a true beginner, you may be interested in some training. Visit www.pdfscripting.com , you may find it well worth the membership fee if you are going to be developing more PDF forms.

Also, as gkasieril mentioned there are 70 or more tutorials on a wide variety of scripting topics for both Acrobat and LiveCycle Designer PDF forms here at AUC in the Learning Center. Many of those tutorials include download files so you can examine the scripts. You may also want to spend some time checking out the sample files in the Forms Gallery here- they will give you lots of ideas of what can be done with PDF forms.

Hope this helps,

Dimitri
www.pdfscripting.com
www.windjack.com
Thanks for your offer however i was hoping i'd get some advice not a sales pitch.

thanks

Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi digitalwiz,

I really wasn't trying to "sell" you anything. I can see why you might think that though. But with questions you are asking like where to place scripts and the fact you stated you were new to scripting and spending hours looking for exact solutions to fit your case, I thought you might be interested in a good training resource. I truly was just trying to make a helpful suggestion as the pdfscripting.com site is pretty much the only on-line resource with comprehensive training videos on this topic. If completing your projects just using the forums here works out for you that's fine, no worries.

Good luck with your project.

Dimitri
www.pdfscripting.com
www.windjack.com
drlau
Registered: Jul 9 2009
Posts: 2
digitalwiz wrote:
George_Johnson wrote:
Do you want the export value of the combo box item that is selected to appear in the text field (e.g., 1), or do you want the "face value" (e.g., "test") to appear?To set the Keystroke script in a combo box, select a Format type of Custom and you'll see where you can enter the script.
Ideally Gorge, I would like to be able to select and item in the combo box and have a number of text fields change to different text sentences based on the item chosen from the combo box.
Hi digitalwiz,

I think I understand what you are trying to do.

Here is a quick-n-dirty way to accomplish what I think you are asking, using a calculation script.

In the combo box's Options tab, make sure the "Commit selected value immediately" checkbox is checked.

In the "Calculate" tab of the text box, enter this into the "Custom calculation script":

// Get comboBox value and hold as a variable
var cb1Choice = this.getField("comboBox1");

// Check the value and display the appropriate text
if (cb1Choice.value == "1")
{
event.value = "Relevant text message 1.";
}
else if (cb1Choice.value == "2")
{
event.value = "Relevant text message 2.";
}
else if (cb1Choice.value == "3")
{
event.value = "Relevant text message 3.";
}


You will need to do this for each text box you want to react to the choice made in comboBox1.

I hope this helps with what you are trying to do.

drlau

P.S.: I found Ted Padova's 101 tips pdf to be quite valuable when I first started learning javascript (still learning!).