Copy link to clipboard
Copied
I made a "DropDown1" with 2 choices based in differente attributes "ValueInt"and "ValueCon" to populate a "Text2".
My issue is that no matter my choice in the Dropdown, it will always get the "var con"
Any help to make the code get the correct var for each option?
var int = getField("ValueInt");
var con = getField("ValueCon");
var HPAtrib = { "Administração (Int)":{ atrib: event.value = Math.round(int.value * 1) },
"Medicina (Int)":{ atrib: event.value = Math.round(con.value * 1) }};
function SetFieldValues(cHpa)
{
this.getField("Text2").value = HPAtrib[cHpa].atrib;
}
Using a data object is really just complicating things for you here.
Use this instead:
function SetFieldValues(cHpa) {
var int = Number(this.getField("ValueInt").valueAsString);
var con = Number(this.getField("ValueCon").valueAsString);
if (cHpa=="Administração (Int)")
this.getField("Text2").value = Math.round(int);
else if (cHpa=="Medicina (Int)")
this.getField("Text2").value = Math.round(con);
else this.getField("Text2").value = "";
}
Here you go...
Change the doc-level script to this:
function SetFieldValues(cHpa, targetFieldName) {
var int = Number(this.getField("ValueInt").valueAsString);
var con = Number(this.getField("ValueCon").valueAsString);
if (cHpa=="Administração (Int)")
this.getField(targetFieldName).value = Math.round(int);
else if (cHpa=="Medicina (Int)")
this.getField(targetFieldName).value = Math.round(con);
else this.getField(targetFieldName).value = "";
}
And then use just this code from the fields:
SetField
...Copy link to clipboard
Copied
It finally worked! You are a life saver. Thank you very much!
Copy link to clipboard
Copied
Unfortunately, I had another issue with my form...
I send the file attached.
I need the field "ccAtrib.0" to be filled with the numbers in the fields "ValueFor" or "ValueDes", based in the Dropdown "HabCC.0" choice.
I did get the filling fields to be filled right, but the code for calculation you previously did for "ccAtrib.0" isn't working anymore, so "ccAtrib.0" isn't beeing filled with the values of "ValueFor" and "ValueDes".
Another issue is that the fields "HabCC.0", "gol.0", "apa.0", "dan.0", "HabCCCusto.0", "HabCCNivel.0", "HabCCG.0", ""HabCCA.0" and "HabCCD.0"will be MULTILINE, around 100 rows...
Can you please have any idea to make it work?
Copy link to clipboard
Copied
Check the JS Console. You have errors in your code.
So what's your question about the multiline fields?
Copy link to clipboard
Copied
Check the JS Console. You have errors in your code.
By @try67
That is one of my issues. You mean the Debugger console, right? Well, when I execute the script in the debugger it won't return an error for me to fix. So I am missing my errors. I reviewed the code several times, and I can't find them myself, as I said before I am a beginner with javascript, for my desperation. The code you gave me before works for another page of my form like a charm, but i am not getting to make it work in this new example I sent for you.
So what's your question about the multiline fields?
By @try67
I managed to make the format custom keystroke to work for the original line. But when I create multiple copies of that line, the JS Document Level function will not work, because of the name of the 3 fields It fills. The line multiplication will change the names of the fields, adding a .x number in the end, that indicates the number of the line. This is the function:
function SetFieldValues(cMelee)
{
this.getField("gol.0").value = CCData[cMelee].golpe;
this.getField("apa.0").value = CCData[cMelee].aparo;
this.getField("dan.0").value = CCData[cMelee].dano;
}
as you see, this.getField("gol.0").value is one of the issues I mentioned. As I wrote it (based in an example I found in a book), I would have to write a new function for each line, because I don't know to to make adobe detect the multiline. Can you tell me a way to make the names of the fields "gol.0", "apa.0"and "dan.0" update for the new line numbers without having to add a newu function for each line?
Copy link to clipboard
Copied
- The debugger and console share the same window, but are not the same thing.
See: https://acrobatusers.com/tutorials/javascript_console
The specific error message I'm getting is:
TypeError: this.getField("ValueInt") is null
6:Field:Calculate
- You can pass the index number as a parameter to the function, and then use it in the code to access the relevant fields.
Copy link to clipboard
Copied
- You can pass the index number as a parameter to the function, and then use it in the code to access the relevant fields.
By @try67
With a code like the one below?
oFld = event.target.name;
var nNumRow = oFld.substring(oFld.lastIndexOf('.')+1);
Copy link to clipboard
Copied
Yes, that's one way of doing it.
Copy link to clipboard
Copied
Is there a better option than this?