These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Need help fixing this code

MelMuff
Registered: Feb 2 2010
Posts: 11

I am trying to get this code to work using "if else statment" but it will only do the first part and not do the second part in the else statement. Can anyone help me out because I need to finish this today for work? Here is the code:

var R1 = this.getField("Registration Fees1");
var R2 = this.getField("Registration Fees2");
var R3 = this.getField("Registration Fees3");
var R4 = this.getField("Registration Fees4");

var R0 = 0

if (R0 == 0)
{
event.value = Math.floor(R1.value);
}
else
{
event.value = Math.floor(R2.value + R3.value + R4.value);
}

My Product Information:
Acrobat Pro 9.2, Windows
MelMuff
Registered: Feb 2 2010
Posts: 11
I did notice that if I fiddled around this this part:

if (R0 == 0)

sometimes I can get the second part to work but not the first. I need it to do either or and this is getting frustrating. Any help would be greatly appreciated. Thanks in advance.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Carefully read your code. R0 is always zero so the 'if' statement will always evaluate to true.

Quote:
var R0 = 0; // set the value of R0 to zero
// test if R0 is zero
if (R0 == 0) {
// when R0 is set to zero
event.value = Math.floor(R1.value);
} else {
// if R0 is not set to zero
event.value = Math.floor(R2.value + R3.value + R4.value);
}

George Kaiser

MelMuff
Registered: Feb 2 2010
Posts: 11
Thanks gkaiseril. I do understand that. I just don't understand how to get this to work. I might not even need "var R0 = 0". I just threw that in there for the condition part. I am not that diverse in java script so that's why I am having trouble with it. I can take "var R0 = 0" out. But then what should the condition be? Basically, in the form, the default is 0 and then the calculation follows by user clicking on different prices. The first part is if they want to pay for the full conference and the second part is if they want to pay for either Monday, Tuesday or Wednesday or 2 of the 3 days. Is it possible to get this to work with both parts together? I am still stuck on getting just one or the other working.
MelMuff
Registered: Feb 2 2010
Posts: 11
No hurry to finish this today now. I have been given an extra day extension. Phew! However, I still need help on this. :)
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
So you have 4 check boxes:

Registration Fees1 - all 3 days
Registration Fees2 - Monday
Registration Fees3 - Tuesday
Registration Fees4 - Wednesday

If 'Registration Fees1' is checked this is the fee otherwise the fee is the sum of the other check boxes that are selected.

You need to be aware that the value of the an unselected check box or radio button is 'Off'.
// all four daysvar R1 = this.getField("Registration Fees1").value;// Mondayvar R2 = this.getField("Registration Fees2").value;// Tuesdayvar R3 = this.getField("Registration Fees3").value;// Wednesdayvar R4 = this.getField("Registration Fees4").value;var Fee = 0event.value = ''; // default valueif (R1 != 'Off') {Fee = Number(R1) + Fee;} else {if(R2 != 'Off') {Fee = Number(Fee) + R2;}if(R3 != 'Off') {Fee += Number(R3);}if(R4 != 'Off') {Fee = Number(R4) + Fee;}}event.value = Fee;

George Kaiser

MelMuff
Registered: Feb 2 2010
Posts: 11
Thankx gkaiseril. It's still not working but I will study this code and see if I can get it to work.
MelMuff
Registered: Feb 2 2010
Posts: 11
I still need help with this. I have fiddled around with the code but I still cannot get it to work.