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

getField(event.target.name) concatenation script assistance

rabdullah
Registered: Jul 7 2009
Posts: 14

I have a form that has several fields with similar/identical names psv1.0 psv1.1 and corresponding edv1.0 edv1.1 fields etc created using the place multiple fields option in Acrobat 9. My question in pseudo code if I may ( scripting newbie).

Is that I want every time I enter a value in edv1.0 the corresponding psv1.0 to be required. and not all psv's becoming required as I have it now.

function psvRequired()
{

var psv = this.getField("psvTL1.0");
psv.required = true;
psv.hidden = false;
psv.borderColor = color.red;
}

I know that the event.target.name is my friend because if I use that, I can concatenate everything in the first three letters in my string and that would solve the problem but I dont know how to and googling is not helping me much. Please assist

My Product Information:
Acrobat Pro 9.0, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
With a function, you can pass a parameter that will be used within the function. This can be a value or an object.

So if one passes the name of the 'edv1' field:

function psvRequired(cEdv1Name) {// make edv1 name into an array splitting at '.'var aEdv1 = cEdv1Name.split('.');// construct the 'psvTL1.#' with '#' from the 'edv1' array - element 1var cFieldName = 'psvTL1.' + aEdv1[1];// get psvTL1.# field objectvar oPsvTL1 = this.getField(cFieldName);oPsvTL1.required = true;oPsvTL1.hidden = false;oPsvTL1.borderColor = color.red;return;}

And then one could call the function in any of the 'edv1' fields with
psvRequired( event.target.name);

George Kaiser

rabdullah
Registered: Jul 7 2009
Posts: 14
first things first, thank you for your response, unfortunately I use BFO which causes significant problems with forms that use Arrays, is it possible to do it with just strings that outputs the fieldName with getField then concatenates that output?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Your coding example showed the use of the hierarchical field naming technique, which I used to simplify the code to automatically determine the number of fields in the lower group of fields and one would not need to change the code for the varying number of possible fields.

You can modify the code as necessary to specify the number of items to process and the strings to use.

George Kaiser

rabdullah
Registered: Jul 7 2009
Posts: 14
ok, maybe another approach, for example when i do,

function listedvFormFields()
{
var alledvFields = "";

for (var i = 0; i < this.numFields; i++)
{
var newField = '"' + this.getNthFieldName(i) + '" '; // how do I specify the field range here?
alledvFields += newField;
}
app.alert(alledvFields);
}

I am able to get all the field names.. the coding you specified uses the split method which unfortunately does not work with BFO. so I was thinking if I can just get to a point where I can perform the same task as above without it printing all fields and just the edv fields, I can concat them individualy as strings.
rabdullah
Registered: Jul 7 2009
Posts: 14
hmm maybe I am off base here..... it looks like I would have to loop through all the fields(despite being inefficient) then select the specific fields "edv1.0" and THEN concatenate with the corresponding psv1.0 field