getting value of form field and its name

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

joeitaliano
User
Posts: 89
Joined: Wed Dec 29, 2010 8:50 am

getting value of form field and its name

Post by joeitaliano »

hello

i want to extract the value of all the form fields so i have written this code. if there is a different function/better way to do it please let me know

BSTR RESULT;

BSTR Mem1 = SysAllocString(L"var count = 0; count = this.numFields;");
m_spView->RunJavaScript(Mem1, &RESULT, 0, 0);
SysFreeString(Mem1);

int icount = _wtoi(RESULT); i NOW HAS THE NUMBER OF FIELDS IN THE FORM

for (int j=1; j<icount; j++) {
CString JavaString;
JavaString.Format(L"var fname = this.getNthFieldName(%d);var f = this.getField(fname);f.value;", j); THIS DOES NOT WORK
// JavaString.Format(L"var fname = this.getNthFieldName(%d);var f = this.getField(fname);f.name;", j); THIS WORKS AND RETURN FORM NAME
// JavaString.Format(L"var fname = this.getNthFieldName(%d);var f = this.getField(fname);f.name,f.value;", j); WOULD THIS RETURN BOTH??? NAME AND VALUE
BSTR Mem2 = SysAllocString(JavaString);
m_spView->RunJavaScript(Mem2, &RESULT, 0, 0);
SysFreeString(Mem2);
}

all is fine - until i TRY to return the value of the form field which it is not doing

my preference is to return the name of the form field and its value

thank you in advance

joe italiano
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: getting value of form field and its name

Post by Corwin - Tracker Sup »

Hi joe,

As I have test it, this line

Code: Select all

JavaString.Format(L"var fname = this.getNthFieldName(%d);var f = this.getField(fname);f.name;", j);
works fine. Please make sure that you are using latest build of Viewer. Also you may test JS in standalone Viewer just to check how it works.

Code: Select all

JavaString.Format(L"var fname = this.getNthFieldName(%d);var f = this.getField(fname);f.name,f.value;", j); WOULD THIS RETURN BOTH??? NAME AND VALUE
Using this code you will get only field value.

HTH.
joeitaliano
User
Posts: 89
Joined: Wed Dec 29, 2010 8:50 am

Re: getting value of form field and its name

Post by joeitaliano »

hi corwin

i agree that

JavaString.Format(L"var fname = this.getNthFieldName(%d);var f = this.getField(fname);f.name;", j);

works but the following code does not work and it is the form field value i need

JavaString.Format(L"var fname = this.getNthFieldName(%d);var f = this.getField(fname);f.value;", j); THIS DOES NOT WORK

joe
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19885
Joined: Mon Jan 12, 2009 8:07 am

Re: getting value of form field and its name

Post by Stefan - PDF-XChange »

Hello Joe,

I have asked Corwin to take another look here, but in the mean time please ensure that you are using build 193, as in the end user Viewer at least, using the JS console I was able to obtain both the form name and value.
Image
The file I tried with is this one.

Best,
Stefan
joeitaliano
User
Posts: 89
Joined: Wed Dec 29, 2010 8:50 am

Re: getting value of form field and its name

Post by joeitaliano »

hi stefan

from what i can see i am

i have attached a zip file with the app source

look at the close function or search for f.value dlgdocument.cpp

cheers

joe
You do not have the required permissions to view the files attached to this post.
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: getting value of form field and its name

Post by Corwin - Tracker Sup »

Hello Joe,

And again - all works fine for me (name and value gets fine). Can you please send us sample file where you get such problems?
Also note that annots array is zero based, so if you want to get all annots, you should change your "for" statement:

Code: Select all

for (int j=0; j<icount; j++)
joeitaliano
User
Posts: 89
Joined: Wed Dec 29, 2010 8:50 am

Re: getting value of form field and its name

Post by joeitaliano »

hi corwin

did you test with the source code from the zip file i sent you

joe
joeitaliano
User
Posts: 89
Joined: Wed Dec 29, 2010 8:50 am

Re: getting value of form field and its name

Post by joeitaliano »

all fixed it was the pdf file that was corrupted works ok with the others

thank you all
You do not have the required permissions to view the files attached to this post.
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19885
Joined: Mon Jan 12, 2009 8:07 am

Re: getting value of form field and its name

Post by Stefan - PDF-XChange »

:)