Expand my Community achievements bar.

SOLVED

What is the function to hide all pages in a form?

Avatar

Level 4

Hi

What´s the function that I could use to hide all pages in a form?

For example: when an user to click in a button, I would like to hide all the pages of the form.

Thank you.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

This works because the script within the parentheses {} is re-run until the value of i matches 25.

The loop is constructed in three parts:

var i=1;     This declares the variable i and sets it with an initial value of 1

i <=25;     This is a test, the loop runs until i is greater than 25

i++           This increases the value of i by 1 each time the loop is run

When you put is all together as...

for (var i=1; i<=25; i++)

{

     // script in here will run 25 times

}

If you are using a hidden field for the number of pages, you would set this with a default value at design time (Object > Value palette). Then the for statement would look like this:

for (var i=1; i<=totalNumberPages.rawValue; i++)

You do not need to alter the i variable at all.

Hope that helps,

Niall

Assure Dynamics

View solution in original post

13 Replies

Avatar

Level 10

Hi Rafael,

You can change the presence property for each page, eg:

page1.presence = "hidden";

However you need to set up the pagination for each page to "Follow previous". The next problem is that this will hide all of the pages, but you will be left with one blank Master page.

So you could set up an additional page (that would normally be hidden) and then make this visible as you hide the others. This page could contain instructions or a simple message. Another option is that you could have a rectangle covering the page that takes a fill colour to match the version of Acrobat/Reader, giving the impression that all pages are hidden.

Hope that helps,

Niall

Assure Dynamics

Avatar

Level 4

Hi Niall. How are you my friend?


Then, look what I would like to do.

I will do a guide. In this guide will have a principal page with the links/subject - when the user open the file. When the user to click in some subject, all the pages of this subject would appear and then others became hidden... And so on...


Looks like a website in HTML...


I could set hidden each page (it will works too), but the work is hard. For example, if I put a new subject, I will change all over script. Then if it has a function that hidden all pages, will be easier.

Example:

[Start script]
User click some subject
function hidden all pages
some_subject.presence = "appear";
[End script]


Sorry my English, I know is very bad lol


Thanks

Avatar

Level 10

Hi Rafael,

You could try a loop. This would work best if all of the pages had a common string at the start, followed by a number. E.g. page1, page2,... page99.

This way you would hide all of the pages using the loop and then re-show the appropriate page.

Then all you would need to do is change the number in the loop, which you could do using a global variable.  This would work for 25 pages:

for (var i=1; i<=25; i++)

{

     xfa.resolveNode("page" + i).presence = "hidden";

}

// then show the page you want for that button

page12.presence = "visible";

As I say you could use a global variable in the File > Form Properties > Variables tab or set up a hidden numeric field to hold the number of pages in the form. OR you could have the hide script as a function in a script object and call this from any of the buttons. This would mean that you have one hide script in one location, which will be easier to maintain.

The function in the script object (customScript) would look like this:

function hidePages()

{

     for (var i=1; i<=25; i++)

     {

          xfa.resolveNode("page" + i).presence = "hidden";

     }

}

Then the script in the click event of the button would look like this:

customScript.hidePages();

page12.presence = "visible";

Hope that helps,

Niall

Assure Dynamics

Avatar

Level 4

Hello Niall.

I think this better soluction for my problem

for (var i=1; i<=25; i++)
{
     xfa.resolveNode("page" + i).presence = "hidden";
}

// then show the page you want for that button
page12.presence = "visible";

But I didn´t understand how it works. I will create a field hidden to put the number loop (for me is the way easier). Then, always I have to change the value of the "i" to 1?? The var i has to stay inside of the loop?  It´s correct?

Thank you.

Avatar

Correct answer by
Level 10

Hi,

This works because the script within the parentheses {} is re-run until the value of i matches 25.

The loop is constructed in three parts:

var i=1;     This declares the variable i and sets it with an initial value of 1

i <=25;     This is a test, the loop runs until i is greater than 25

i++           This increases the value of i by 1 each time the loop is run

When you put is all together as...

for (var i=1; i<=25; i++)

{

     // script in here will run 25 times

}

If you are using a hidden field for the number of pages, you would set this with a default value at design time (Object > Value palette). Then the for statement would look like this:

for (var i=1; i<=totalNumberPages.rawValue; i++)

You do not need to alter the i variable at all.

Hope that helps,

Niall

Assure Dynamics

Avatar

Level 4

Helllo!

I am here to thank for your attention with all over user this forum! Congratulations Niall. You are always helping everybody here with a lot of dedication, education and many wisdom!

Thank you very much! Keep it up!

I will test your script soon.

I chose your answer as correct.

See ya

Avatar

Level 4

Hi Niall.

Niall, I am sorry to up this post, but just today I had time to work arond my form.

So, I tryed to use your example using the function, but I couldn't to do it works.

What's part of form I have to put this script:

function hidePages()
{
     for (var i=1; i<=25; i++)
     {
          xfa.resolveNode("page" + i).presence = "hidden";
     }
}

What language do I have to use (FormCalc or JavaScript)

Thanks so much

Avatar

Level 4

Niall, sorry.

One more question.

I wanna put names in my pages, but my form just works using your solution, if I put my pages  this way: page1, page2...

Ok, but I am thinking about to put in this way: nameofpage_1. Then, is there some function that give the value before "_"? This way, I would take the names of my pages and I would put the number to hide it.

Avatar

Level 10

I've closed down here, but can you share your form?

If so, upload it to a file sharing site, like acrobat.com and then post the

published URL here.

I'll try and have a look over the next few days.

Niall

Avatar

Level 4

Hi Niall.

I am Sorry, but unfortunatly I can't post this form because this form is a project and has a brand of the company where I work and then I would has problem with this. My form is all over in Portuguese too.

Please, I hope you sorry me and again, thanks a lot of you attention in help me.

Do you prefer I open another post?

Thanks.

Avatar

Level 4

Hi Niall.

If you give me a example, I am sure that I can resolve it.

Avatar

Level 10

Hi Rafael,

There is an example here , which is set up with 5 pages.

Hope that helps,

Niall

Assure Dynamics

Avatar

Level 4

Hi Niall!!

Thanks a lot of your attention. I can use your example and and the same time I learned to use the Global Object!!!

Thank so much!

What you do here in this Forum it is very helpfull!

Have a nice Monday!

Sorry again for up this post.