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

Javascript "if else" statements

benz862
Registered: Mar 5 2008
Posts: 10

Hello people, I hope you can help me on this one.

I have two subforms, one with an already populated drop-down list of peoples names and in the second subform I have an numeric box.

Is there a way that I can have a certain name once selected from the drop-down list, to populate the numeric box with a set number, but doing so only allows a limit of what numbers (i.e. 0 to 10) to be inserted?

Essentially what I am getting at is when you select "John Doe" from the drop-down list he is only allowed to give up to a 10% discount, whereas "Sandra Smith" is allowed to give up a 15% discount.

So I think I need something that says if John Doe enters a value that is ≥ 11 then he can't but of course Sandra could.

Understand? I hope someone can help, thanks in advance.

My Product Information:
LiveCycle Designer, Windows
benz862
Registered: Mar 5 2008
Posts: 10
Thank you for your reply, but it is still not working. Here is the actual code.


if (RepName.rawValue == "Jane Doe"){
xfa.form.TableSubForm.Table.HeaderRow[0].Discount.rawValue = 10;
}

Where "RepName" is the name of the drop-down list and "Discount" is the cell within the first Header Row, within the Table, within it's own subform.

I tried to change "RepName" to "this", but still it doesn't seem to be working.

Thanks in advance.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
If you do not need the names from the drop down elsewhere, you can set the export value for each entry to the discount amount. This would allow one to use the drop down box value directly. If you have a large number of selections you might consider using the "switch{}" statement instead of the nested "if" statement.

switch (RepName.rawValue) {
case "Jane Doe":
xfa.form.TableSubForm.Table.HeaderRow[0].Discount.rawValue = 10;
break;
case "John Doe":
xfa.form.TableSubForm.Table.HeaderRow[0].Discount.rawValue = 15;
break;
default: // no match found - no discount
xfa.form.TableSubForm.Table.HeaderRow[0].Discount.rawValue = 0;
break;
} // end switch RepName

George Kaiser

benz862
Registered: Mar 5 2008
Posts: 10
Thank you both very much for your replies, they are appreciated. I finally got it to work by this means;

var sNewValue = this.boundItem(xfa.event.newText); // get the value associated to the item that was picked
var aInfo = sNewValue.split("|"); // aInfo becomes an array of string tokens from the new value

// populate the ItemNumber and InfoPrice fields with their respective values
RepCell.rawValue = aInfo[0]; // first element is the item number
TableSubForm.Table.HeaderRow.Discount.rawValue = aInfo[1];


but this still leaves me in a bit of a quandary for the "Discount" field. Is there a way that if a certain name has been selected via the drop down list, let's just say "Jane Doe", that her maximum discount value cannot exceed 10 percent. So in this case Discount.rawValue ="10"

I need a way to stop her from inserting a value that is ≥ 11. Is there something I can do in either the drop down list field or the Discount field that would enable a message, as well as change her value at something that is either 10% or lower in the Discount box?

Any help here would be greatly appreciated.

Of course, the drop down list would have a selection of 20 people or so, each with their respective discount rates. Please note, that the drop down list is located in "HeaderSubForm" whereas "Discount" is located in "TableSubForm".

Thank you!