Expand my Community achievements bar.

How to access form variables?

Avatar

Level 2

I have created a form variable named customerData like this

{
  data: "faraz",
  cPage: 1,
  tPages: 3,
  showData: function() {alert('in show data');},
  showPager: function() {alert('in show pager');}
};

Now i am trying to access the cPage from onclick of a button with this code

app.alert(customerData.cPage);

but its giving me undefiend.

How to access the cPage, tPages values?

7 Replies

Avatar

Level 10

Try this way..

customerData.cPage.toString();

Thanks

Srini

Avatar

Level 2

Now nothing happened on click.


Avatar

Level 2

You have declared the customerData in the click event of button. I want to write the customerData in Form variable (i.e. global) so that i can access it from any event of any field.

Avatar

Level 10

What I see is when the variable is declared at the form level, it is treated as a String variable. But when I declare the variable inside the click event it is treated as an object. The syntax I sent you will work only if it is an object. Bruce has given some explanation in one of the earlier discussions. I will search and send you why this difference in the behaviour.

Thanks

Srini

Avatar

Level 2

I just found that i need to create variables like this

form1.#subform[0].#variables[0].customerData - (JavaScript, client)

var data= "faraz";
var cPage= 1;
var tPages= 3;
var showData= function() {app.alert('in show data');};
var showPager= function() {app.alert('in show pager');};

then i can access from anywhere like this

customerData.showPager();

or

app.alert(customerData.data);

Avatar

Level 10

Here is the old thread where Bruce explained in detail.

http://forums.adobe.com/message/2463978#2463978

Thanks

Srini