Hello
I have a form with two lists. Is it possible to populate one list based on the selected value in the other one?
Much appreciated
//JavaScript code, and you could change it accroding to your specific requirement.
String script
= "var Fruits = [\"Apple\", \"tangerine\"];"
+ "var Vegetables = [\"lettuce\", \"Cabbage\"];"
+ "var v = event.value;"
+ "var List2 = this.getField(\"ListBox2\");"
+ "if (v == \"Fruits\")"
+ "{"
+ "List2.setItems(Fruits);"
+ "}"
+ "else if (v == \"Vegetables\")"
+ "{"
+ "List2.setItems(Vegetables);"
+ "}";
PdfJavaScriptAction action1 = new PdfJavaScriptAction(script);
PdfDocument pdf = new PdfDocument(@"F:\testing\ListSample.pdf");
PdfFormWidget formWidget = pdf.Form as PdfFormWidget;
//get the ListBox1
PdfListBoxWidgetFieldWidget list = formWidget.FieldsWidget.List[0] as PdfListBoxWidgetFieldWidget;
//set the JS to the ListBox1
list.Actions.KeyPressed = action1;
pdf.SaveToFile("10678.Pdf");
//case#1
AFSimple_Calculate("SUM", new Array("Text1", "Text2"));
//case#2
var one = this.getField("Text1");
var two = this.getField("Text2");
this.getField("total").value = one.value + two.value;
//case#1 "Text1" and "Text2" are the name of TextBoxs
String script = "AFSimple_Calculate(\"SUM\",new Array(\"Text1\", \"Text2\"));";
PdfJavaScriptAction action = new PdfJavaScriptAction(script2);
PdfDocument pdf = new PdfDocument(@"F:\testing\CalculatJsSample.pdf");
PdfFormWidget formWidget = pdf.Form as PdfFormWidget;
//get the total textbox field
PdfTextBoxFieldWidget textbox = formWidget.FieldsWidget.List[4] as PdfTextBoxFieldWidget;
textbox.Actions.Calculate = action;
//if the textboxs already have values, Spire.PDF doesn't calculate that values firstly, so set the code below.
PdfTextBoxFieldWidget textbox2 = formWidget.FieldsWidget.List[2] as PdfTextBoxFieldWidget;
PdfTextBoxFieldWidget textbox3 = formWidget.FieldsWidget.List[3] as PdfTextBoxFieldWidget;
textbox.Text = (int.Parse(textbox2.Text) + int.Parse(textbox3.Text)).ToString();
pdf.SaveToFile("10687Calculate1.pdf");