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

can't get field value by javascript

robman
Registered: Sep 18 2007
Posts: 25

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, Windows
pddesigner
Registered: Jul 9 2006
Posts: 858
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
}

My favorite quote - "Success is the ability to go from one failure to another with no loss of enthusiasm.

pddesigner
Registered: Jul 9 2006
Posts: 858
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.

My favorite quote - "Success is the ability to go from one failure to another with no loss of enthusiasm.

danielha
Registered: Jan 7 2008
Posts: 6
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!
KathrynGZ
Registered: Apr 15 2008
Posts: 35
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