Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Assigning global variables

Avatar

Level 2

I apologize if this is a basic and simple question but I have been pulling my hair out for the last week trying to get this to work and Google is getting sick and tired of my questioning them for answers.  This shouldn't be that difficult but I'm not a designer, nor a programmer, I'm just a tech trying to make my people's lives easier, so yes, I brought this upon myself.

I have converted an InDesign form that has a bunch of check boxes into a LiveCycle document.  I want the check boxes when they are checked to assign a value to it's assocated variable.  In the form properties I have set up the global variables and assigned the value of each to "0". 

For the check box I have set the change method/property to have the following code:

if (topmostSubform.Page1.Back_Cover.rawValue==1)

          BC.value=6300;

else

          BC.value=0;

I have a textbox that I am trying to take all of these values and based on what is checked and what is not it should calculate the total for that field.  Here is the code I have for calculating the text value using the calculate method/property:

premium.rawValue = BC.value + IFC.value + IBC.value;  //there are three check boxes associated with this value

However, no matter what I do no values seem to get assigned to the BC variable.

Can someone please point me in the right direction as to why this isn't working?

Thank you very much.

Tom

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I think Steve is right, you want to avoid using global (or form) variables in this case, especially in the calculate event as any changes in there value wont cause a recalculation.  I would also try and keep all the calculation logic in the one place.  So in the calculate event of the premium field I would put the following JavaScript;

this.rawValue = (Back_Cover.rawValue === "On") ? 6300 : 0;

this.rawValue += (Inside_Front_Cover.rawValue === "On") ? 5775 : 0;

this.rawValue += (Inside_Back_Cover.rawValue === "On") ? 5350 : 0;

Note the on/off values of your checkboxes are the strings "On" and "Off".

Bruce.

p.s. Nice looking form

View solution in original post

0 Replies

Avatar

Level 10

Hi Tom,

Try

if (topmostSubform.Page1.Back_Cover.rawValue==1) then

          BC.value=6300;

else

          BC.value=0;

endif

That is with a "then" and an "endif"

Also, make sure you have "Show console on errors and messages" in Acrobat/Reader JavaScript preferences.

Regards

Bruce

Avatar

Level 2

I originally had that and various threads and forums pushed me to the above format.  Regardless, I changed it and still have a zero value for the premium.rawValue when I do the calculation.

For a little more information, when I enter values for the variables in the Form Properties, the premium.rawValue does calculate everything correctly so it seems to be a problem with reassigning the value to the global variable.

Thanks for your response.

Tom

Avatar

Level 10

Hi,  I guess I assumed you were using FormCalc but are you using JavaScript.  Maybe it would be easier to understand what is happening if you could publish the form somewhere and provide a link in this thread.  Bruce

Avatar

Level 5

Did you to keep message boxes or alerts in the loop.and try to display the global values.

Avatar

Level 2

Sorry, I have been out a while due to surgery but I'm back on track now.

I have uploaded this file to my dropbox account and it is available here.

I have only put code in for the first couple of checkboxes and the textbox to the right of it.  I don't know why it isn't updating the global variables.  I also upgraded my version of LiveCycle to ES2 wondering if that could be the problem...it isn't.

Any insight into what I'm doing wrong would be greatly appreciated.

Thanks for your patience.

Tom

Avatar

Level 6

Drop box is blocked for me.

rawValue is not changed yet in the change event. You need to use xfa.event.newText.

The global variable thing seems a waste to me. Can't you just reference the rawValue of each check box in the calculate event of the text field?

Avatar

Level 2

I guess I'm not understanding...sorry.

I'm using a check box to set a value, i.e. if checkbox1 is checked then value a=100, if checkbox2 is checked then value b=300 therefore the calculate of textbox1=value a + value b (400).  I used the change event for the checkboxes to assign the values and the calculate event of the textbox to total everything up but when I tried to do it locally it didn't work and I read a posting saying that I had to use global variables so, hence, I headed that way.

Thanks

Avatar

Correct answer by
Level 10

Hi,

I think Steve is right, you want to avoid using global (or form) variables in this case, especially in the calculate event as any changes in there value wont cause a recalculation.  I would also try and keep all the calculation logic in the one place.  So in the calculate event of the premium field I would put the following JavaScript;

this.rawValue = (Back_Cover.rawValue === "On") ? 6300 : 0;

this.rawValue += (Inside_Front_Cover.rawValue === "On") ? 5775 : 0;

this.rawValue += (Inside_Back_Cover.rawValue === "On") ? 5350 : 0;

Note the on/off values of your checkboxes are the strings "On" and "Off".

Bruce.

p.s. Nice looking form

Avatar

Level 2

Thank you very much for your assistance.  This was exactly what I needed/was looking for.  I knew that it had to be something simple/logical that I was missing.  I like your coding, very streamlined.

Thanks again.