Accessing form data via Javascript. | Community
Skip to main content
July 16, 2007

Accessing form data via Javascript.

  • July 16, 2007
  • 15 replies
  • 10844 views
Hi,



I'm completely stuck. I have a form with a table with a row containing a textfields. I'm able to add rows to that table via JavaScript. No problem here. Now I want to populate a dropdown with the data entered into the textfield(s). And Here I'm completely stuck. I don't manage to find the instantiated rows with their Textfields.



The hierchy view shows form1>purchaseOrder>Table1>Row



I tried stuff like this:

'xfa.resolveNodes("xfa.form.form1.purchaseOrder.Table1.Row[0].TextField1").rawValue'

or

'xfa.form.form1.purchaseOrder.Table1.Row[0].TextField1'

to access the node or the field without succces.



Nor do I find the way to get a count of the instantiated rows, so I could loop through them.



Thanks in advance

(a desperate)

Steven
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

15 replies

Adobe Employee
July 17, 2007
Tables can be confusing to use sometimes, especially through script!



I created a simple 3x3 table. That means I have a header row and three rows.



If you want to get to an element of that table, you can use the follwing syntax:



xfa.resolveNodes("form1.Table1.Row" + i + ".Cell1").item(0).rawValue;



where i is the row you are looking for.



Now the question is how do I know how many rows I have?



Since all the rows are really subforms from the Table1 subform, you can get the number of children from that object with the following script:



var objTable = Table1.nodes;

app.alert(objTable.length);



In this case you'll get 8 objects because there is really 4 rows (including the header row) and they each have a corresponding instance manager object called _nameOfSubform, but you should still be able to deduct the number of rows.



There might be a better way that I'm not aware of. Maybe the people in the Designer Forum would know.



Jasmin
Level 10
July 18, 2007
Hi Jasmin/Steven



I don't have my machine with me at the moment, but here are a couple of points from memory:

The expression is not quite right if you're using "repeating" rows. I believe it should be:

// To get the value of a particular cell, called "Cell1"

xfa.resolveNode("form1.Table1.Row[" + i + "].Cell1").rawValue;

// Note: Node not Nodes, and square brackets.



If you want the number of rows, you can use the following expression:

var cells = xfa.resolveNodes("form1.Table1.Row[*].Cell1").rawValue;

var count = cells.length;

// Can't remember if it's length, size, or something else. Code inspector should get it right.

// You can also use the following to get at the i-th cell in the array of values:

var cell_value = cells.item(i);



You may need to tweak my code a little if my memory has not served me well.



Howard

http://www.avoka.com
Level 2
May 20, 2009

Hello Howard ,

I am intrest in this script :

var cells = xfa.resolveNodes("form1.Table1.Row[*].Cell1").rawValue;
var count = cells.length;

Is there a way to filter the data in that field without looping the whole table.

Best regards

Adobe Employee
July 18, 2007
Howard,

I agree with your code there (xfa.resolveNode("form1.Table1.Row[" + i + "].Cell1").rawValue;)



but for some reason that didn't work. I had to use the code I posted instead.



I'm not sure if it's because of the table control or something, but the expression was a bit different than usual.



Jasmin
Level 10
July 18, 2007
Hi Jasmin

Just tested this.

You do need to save the form as a dynamic pdf.



// Row count

var mynodes = xfa.resolveNodes("form1.page1.Table1.Row1[*].TextField1");

tfRowCount.rawValue = mynodes.length;



// Cell value

var cellvalue = xfa.resolveNode("form1.page1.Table1.Row1[" + i + "].TextField1").rawValue;



I can post this somewhere if you want.



Steven - note that you only need to use xfa.resolveNode if you have an embedded array parameter [..]. Otherwise you can just use form1.page1.Table1.Row1.TextField1. This will always get you the first row's value.



Howard
July 18, 2007
Thanks a lot. I knew it couldn't be that hard. I just didn't seem to find the right syntax. I got it to work.<br /><br />This is how I tested it:<br /><br />var mynodes = xfa.resolveNodes("form1.scripting.Table1.Row[*].txtRow");<br /><br />for(i=0;i<mynodes.length;i++)<br />{<br /> var cellvalue = xfa.resolveNodes("form1.scripting.Table1.Row["+i+"].txtRow").item(0).rawValue; <br /> FFResult.rawValue += " - "+cellvalue;<br />}<br /><br />And Jasmin's code did the job. I don't get the value if ommit the "item(0)" in the 'xfa.resolveNodes("form1.scripting.Table1.Row["+i+"].txtRow").item(0).rawValue'<br /><br />Anyhow thanks again<br />Steven
Level 10
July 18, 2007
Hi

Just one other thing...

Don't declare a variable of "nodes" instead of "mynodes". "nodes" appears to be an implicitly defined variable, and if you try to use it, all sorts of weird stuff happens.

Took me 3 hours to find that one :-S

Howard
July 19, 2007
Hi,



I stumbled on a new problem.



This is what I want to do.

1.I have a table:tableEntry, I have a textField=txtDescription in a row=rowEntry and a button=btnRemoveRow for removing the row.

2. I have a tableTarget with rowTarget and within the row a dropdownlist=ddlTarget.

3. Now each time a add a row in the tableEntry and enter data txtDescription I populate the ddlTarget for each row in the tableTarget. That's why I needed the previous code. This works.

4. The user can now select a value from the ddlTarget.



5. A user now edits the data in txtDescription

6. The ddlTarget is updated with the edited value



Now my problem. When I look at the code on the click event on the btnRemoveRow for removing a row in the tableEntry I see this:

_rowEntry.removeInstance(this.parent.index);

so I presume that "this.parent.index" holds the reference for the row I'm working in. Thus when I add an "exit" event on my txtDescription field, I (should) know what row I'm working in via "this.parent.index". So I can loop through the rows in tableTarget and update the appropriate dropdown item.



But this doesn't seem to work. I really don't get how the DOM works in lifecycle designer.



this is the code I used to test:

form1.Page1.tableEntry.rowEntry.txtDescription::exit - (JavaScript, client)

xfa.host.messageBox(this.parent.index);



Steven
Level 10
July 19, 2007
Hi Steven

Welcome to the wonderful world of Javascript.



Try this:

xfa.host.messageBox("Index:" + this.parent.index);



Not 100% sure why this works better, but it's something to do with Javascript's loose typing, and forcing index to be displayed as a string by concatenating.



Howard

http://www.avoka.com
July 19, 2007
DJEEZ!!!

It actualy works like this.



So my code worked all the time, but it's the messageBox that has a ...euh "feature" :-)



thanks
Level 10
July 19, 2007
PS Like Jasmin says, you're probably better off posting this on the LiveCycle Designer Forum.