Trying to access a value using javascript

I have 2 issues;I am trying to get the value of a computed for display number field on the web form.

I have this code in the JS header, the value of the PageNumber field = 5 yet it does not work, if I give it a 5 var lastPage = 5 then it works, but if I use document.forms[0].PageNumber.value then it does not work.;

var form = document.forms[0];

var currentPage = 1;

var firstPage = 1;

var lastPage = document.forms[0].PageNumber.value;

the other problem is that I need to hide the submit button until the last page… the page number may and will change.

thanks,

A.

Subject: Trying to access a value using javascript.

Hi

These are not issues.

Consider learning about ‘computed for display’ fields, the JS header property,

javascript (ecmascript) and about the ‘pass thru HTML’ property.

Sorry.

ian

Subject: RE: Trying to access a value using javascript.

Seriously - In the amount of time it took you to flame this person, you could have helped them. If you don’t have anything constructive to add to the forums, keep your comments to yourself.

Subject: RE: Trying to access a value using javascript.

Ian, Maybe you should not be so quick at judging! We all are at the level that we are at.

Subject: Trying to access a value using javascript.

Notice that:

var lastPage = 5;

and

document.forms[0].PageNumber.value;

are very different sentences. The first one is a simple variable assignment, in the second you are getting the field’s value.

In order to obtain the value of PageNumber field, you have to mark the “Generate HTML for all fields” in the form’s properties box (second tab).

Then, you can do this: document.forms[0].PageNumber.value.

To accomplish the other issue, you have to use “Hide-When Formulas”. Put the cursor in the same paragraph as the submit button, and open the Text properties box on the penultimate tab.

On the field “Hide paragraph if formula is true” write:

PageNumber = 5.

I hope to help you!

Matias

Subject: RE: Trying to access a value using javascript.

thanks,

I did set the form to the “Generate HTML for all fields” but this is still not working

var form = document.forms[0];

var currentPage = 1;

var firstPage = 1;

var lastPage = document.forms[0].PageNumber.value;

any other ideas??

A.

Subject: RE: Trying to access a value using javascript.

Also, instead of this:

To accomplish the other issue, you have to use “Hide-When Formulas”. Put the cursor in the same paragraph as the submit button, and open the Text properties box on the penultimate tab.

On the field “Hide paragraph if formula is true” write:

PageNumber = 5.

I recommend this:

Wrap your button(s) in a tag pair. Then in the JS Header section create a function like this:

function toggleButton(id, PageNumber){

if (PageNumber == 5){

document.getElementById(id).style.display = “inline”;

}else{

document.getElementById(id).style.display = “none”;

}

}

In this way, you can show/hide the button without having to reload the document in a browser.

In your onLoad event, call this function like so:

toggleButton(“subbutton”, 1).

Do this also, for any events that change the value of PageNumber. The reason for the extra parameter of id is to show that the function can be built in a more generic way to encompass other purposes.

Subject: It is just not working…Trying to access a value using javascript.

I have been on the discussion site for hours and found that I am doing what the other are saying but it is just not working for me, so I have placed my code bellow.

In the computed for display field there is a value of 2, so the Next button should be gray out but it goes on, if I set the value to var lastPage =2 then it works but I never know if there will be 1,2 or 6 pages or even more…. So, please … I need help.

This is found in the js header

var currentPage = 1;

var firstPage = 1;

var lastPage = document.forms[0].test.value ;

function flipPage(toPageNumber) {

document.getElementById(‘page_’ + currentPage).style.display = ‘none’;

document.getElementById(‘page_’ + toPageNumber).style.display = ‘block’;

toPageNumber > currentPage?currentPage++:currentPage–;

document.getElementById(‘backButton’).disabled = (currentPage == firstPage)?true:false;

document.getElementById(‘nextButton’).disabled = (currentPage == lastPage)?true:false;

}

This is on my form

→ here I have a computed for display field call test and I can see the value when on the web…(of course it will need to be hidden but right now I am only trying to test my form). The form has “Generate HTML for all fields” set on the form, and the code is pass- thru HTML

Questionaire Page 1

Question 1

Question 2

Question 3

Questionaire Page 2

Question 4

Question 5

Question 6

Questionaire Page 3

Question 7

Question 8

Question 9

Questionaire Page 4

Question 10

Question 11

Question 12

The big “wizardContainer” div is there so that this text will show up above the demo area. Finally, there are the buttons:

Back

Next

Thanks again

A.

Subject: RE: It is just not working…Trying to access a value using javascript.

See if this works for you. It has an advantage of not needing a field to hold lastPage:

onLoad event:

spanArray = document.getElementsByTagName(‘div’);

//for a more complicated document (with additional divs), you would then flip through the divs and check the id to see if it begins with “page” or you could assign all of the page divs a class and use one of the getElementsByClass functions that can be found on the web). The general idea is to get an array of only the divs used for pages.

lastPage = spanArray.length - 1;

JSHeader:

var spanArray;

var lastPage;

var currentPage = 1;

var firstPage = 1;

//var lastPage = document.forms[0].test.value ;

function flipPage(toPageNumber) {

document.getElementById('page_' + currentPage).style.display = 'none';

document.getElementById('page_' + toPageNumber).style.display = 'block';

toPageNumber > currentPage?currentPage++:currentPage--;

document.getElementById('backButton').disabled = (currentPage == firstPage)?true:false;

document.getElementById('nextButton').disabled = (currentPage == lastPage)?true:false;

}

I noticed with both the old method and the one I used, that if you click the button twice in succession rapidly, nothing happens.

Subject: RE: It is just not working…Trying to access a value using javascript.

does your field have an id of test? You might want to add it to the HTML tags too.If this still doesnt work you could define your var in the html head like this ".

I.e. a combination of Formula language and text which should evaluate to your javascript variable.

PS With all the other options, does your test field appear in the browser source?

Subject: RE: It is just not working…Trying to access a value using javascript.

Thanks for all of your help… I got it to work.

One problem is remaining…

Joel To hide the Submit button until the last page I have done this

Wrap your button(s) in a tag pair. Then in the JS Header section create a function like this:

function toggleButton(id, PageNumber){

if (PageNumber == 5){

document.getElementById(id).style.display = “inline”;

}else{

document.getElementById(id).style.display = “none”;

}

}

In this way, you can show/hide the button without having to reload the document in a browser.

In your onLoad event, call this function like so:

toggleButton(“subbutton”, 1).

Do this also, for any events that change the value of PageNumber **************

************** this here , the onclick event is not showing in the options under the form, so I did not add the toggleButton(“subbutton”, 1) anywhere else on the form and the submit is not showing…

any clues how I could do this…

Subject: RE: It is just not working…Trying to access a value using javascript.

While there is an onClick event for the form, it should not be used for this purpose. The call to the function would go in your code that actually flips through the pages (a button or link). The particular call toggleButton(“subbutton”, 1) should go in your onLoad event to do the initial hide of the button when the form loads (because you are on pg 1. Whenever you increment to page 5 (the last page), then you would call toggleButton(“subbutton”, 5) which would pass the value of PageNumber that allows the button span to be visible. The actual function toggleButton(){} will reside in your JSHeader or in a javascript library referenced in the JSHeader.

I’m not sure I mentioned it before, but you would do this INSTEAD of using hide-when formulae. They should be turned off if you are using DOM manipulation to show/hide elements.

Subject: RE: Trying to access a value using javascript.

What kind of fields are these? Are the fields Computed, CFD, or editable? The fields should be CFD or editable. If you wish to store data, they should be editable fields. Computed fields are evaluated as text by web browsers.

Subject: RE: Trying to access a value using javascript.

HImy field is computed for display, I also tried editable and yet it still does not work…

I cannot imagine that this will not work, I could have 5 pages or 8 ro 22… I really need to be able to have a dynamic page number.

It is fustrating as I can see on the form the page number.

any more ideas… should my code be in a differente event Onload or something?

A.