Acrobat User Community Forums

You are not logged in.     Log in to your AUC account.     Don't have an account? Sign up today

#1 2008-01-08 01:18:12

robman
Member
Registered: 2007-09-18
Posts: 10

can't get field value by javascript

how to get the field value? I write a javascript, but can't get field value.
var f = this.getField("DateTimeField1");
app.alert("val:"+f.value);

I find the text of the alert dialog is null. whether the function is not correct or have other function to get a field value in LiveCycle Designer by javascript.


My Product Information:
LiveCycle Designer Standard 8 / Windows

Offline

 

#2 2008-01-08 07:57:31

pddesigner
Member

Registered: 2007-04-24
Posts: 64

Re: can't get field value by javascript

Add a field validator to the text field and try this script.

var t = this.getField("textInput"); // the target field
var cResponse = app.response({
cQuestion: "What do you like about Acrobat?",
cTitle: "Favorite Acrobat feature!"});
{
if ( cResponse == null)
app.alert("Please complete the question."); // if Cancel is selected
else
app.alert("You responded, \""+cResponse+"\", is this correct?",2);
}
t.value = cResponse; // places the data from the dialog to the target field
}

Offline

 

#3 2008-01-08 17:04:51

pddesigner
Member

Registered: 2007-04-24
Posts: 64

Re: can't get field value by javascript

Create a text field and name it (I used target for the name in this example).

Add a button then click the Actions tab for the button Properties (this is done by right clicking the button).

Set the mouse up action and pasting this code for the Add Javascript option:

var t = this.getField("target"); // the target field
var cResponse = app.response ({ cQuestion: "What is your age?", cTitle: "Age Definition",}) ; // title of the dialog box
{
if (cResponse == null)
app.alert ("Please complete the question."); // if Cancel is selected
else
app.alert("You responded, \" "+cResponse+"\" , is this correct?", 3);
}
t. value = cResponse; // places the data from the dialog to the target field

Edit the response message, title, and question.

Note: This is an Acrobat script and it will not work in LiveCycle without modifying this script.

Offline

 

#4 2008-01-08 13:16:59

danielha
Member
Registered: 2008-01-07
Posts: 1

Re: can't get field value by javascript

Eugene,

I tried the code that you sent. I got the following error in the javascript debugger:


this.getField is not a function
1:XFA:form1[0]:#subform[0]:Button1[0]:click
this.getField is not a function
1:XFA:form1[0]:#subform[0]:Button1[0]:click

Here is my javascript code:


var t = this.getField("TextField1"); // the target field
var cResponse = app.response({cQuestion: "What do you like about Acrobat?",cTitle: "Favorite Acrobat feature!"});
{
if ( cResponse == null)
app.alert("Please complete the question."); // if Cancel is selected
else
app.alert("You responded, \""+cResponse+"\", is this correct?",2);
}
t.value = cResponse; // places the data from the dialog to the target field

Any clues? Thanks!

Offline

 

#5 2008-04-15 17:32:13

KathrynGZ
Member
Registered: 2008-04-15
Posts: 28

Re: can't get field value by javascript

danielha,

I just discovered that getField apparently doesn't work in LCD. Instead, you have to use resolveNode. To set the value of a field using resolveNode, you would do something like this:

xfa.resolveNode("[fieldname]").rawValue = "Hello, World";

(Replace [fieldname] with your field name.)

HTH,
Kathryn

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson

AcrobatUsers.com  >>  User Groups • News • Events • Articles • Blogs • How To • Resources • Member Log in