Javascript Cannot Read Property 'showmessagebox' of Undefined
JavaScript Examples
|
These examples illustrate the properties and methods that are supported in this scripting surround. Referencing objectsThese examples illustrate several means to reference an object. When accessing a specific case of an object, be aware of the occurrence number of the object where the script resides. The script volition return the object with the same occurrence number as the object where the script resides. For example, there are three buttons with the same name (Button1[0], Button1[1] and Button1[2]) and three text fields with the same name (TF1[0], TF1[1] and TF1[two]). If the script on Button1[two] is xfa.host.messageBox(TF1.rawValue), the event will be TF1[2].rawValue , and not TF1[0].rawValue. Uses
ScriptsAccessing the first instance of a text field// Admission a sibling field using the field proper name. // Access the first instance of TextField1. TextField1.rawValue = "Hullo"; Accessing the kickoff instance of a text field// Access the kickoff instance of TextField1. When scripting with JavaScript, use // xfa.resolveNode to start the search at the top and movement downwards the form // bureaucracy. xfa.resolveNode("TextField1").rawValue = "Hello"; xfa.resolveNode("TextField1[0]").rawValue = "Hello"; Accessing a field with accessors// When scripting with JavaScript, use the resolveNode() method to admission a // field with a SOM expression that contains a # or [] operator. When searching // with this.resolveNode, the search starts at the current object and moves up // the course bureaucracy. this.resolveNode("Subform2[i].NumericField4").rawValue = 25; Accessing a subform with an index number// Admission a subform with an index number. When using xfa.resolveNode,the search // starts at the top of the form bureaucracy and moves down. var nIndex = ii; var sSOM = "Subform2[" + nIndex + "]"; var oSubform = xfa.resolveNode(sSOM); oSubform.NumericField4.rawValue = "25"; Accessing a field holding// Access a field holding using a property proper noun and value. // Modify the field properties of a specific subform. // Utilize the [] operator to access an object's property. var sProperty = "admission"; var sValue = "readOnly"; // First, get the subform nodes. var oNodes = Subform2.nodes; var nNodesLength = oNodes.length; // Loop through the subform's nodes and look for fields. for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount ++) { // Gear up the field belongings. if (oNodes.item(nNodeCount).className == "field") { oNodes.item(nNodeCount)[sProperty] = sValue; } } Counting the text fields in a document// Count the number of text fields in a document. // Get the field containers from each page. for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) { var oFields = xfa.layout.pageContent(nPageCount, "field"); var nNodesLength = oFields.length; var nCount = 0; for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { if (oFields.item(nNodeCount).ui.oneOfChild.className == "textEdit") { nCount++; } } TextField1.rawValue = nCount; } Accessing fields using partial object names// Access fields using partial object names. // Become the field containers from each page. for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) { var oFields = xfa.layout.pageContent(nPageCount, "field"); var nNodesLength = oFields.length; for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { if (oFields.detail(nNodeCount).name.substr(0,2) == "Te") { xfa.host.messageBox(oFields.item(nNodeCount).proper noun); } } } Accessing a choice list value// Utilize the newText or prevText belongings to access the choice listing value earlier // or subsequently the value changed. // Trigger the script on a modify issue. TextField1.rawValue = xfa.event.prevText; TextField2.rawValue = xfa.event.newText; Accessing a field in a subform// Access a field nested within a sibling subform by prefixing the field proper name // with its parent name. Subform2.TextField3.rawValue = "Hullo"; Accessing fields in a subform// Admission the first-level fields nested within a subform. Subform1.resoveNodes("#field[*]") Getting the fields from each folio// Go the field containers from each page. for (var i = 0; i < xfa.host.numPages; i++) { var oFields = xfa.layout.pageContent(i, "field"); var nodesLength = oFields.length; // Set the access blazon. for (var j = 0; j < nodesLength; j++) { var oItem = oFields.detail(j); if (oItem != this) { oItem.access = "readOnly"; } } } Creating a node in the information modelThis instance illustrates how to create or clone a new data model node. Uses
ScriptCreating a data node// Display the number of kid nodes under the rootNode (xfa.tape). // rootNode is the data file's root node. xfa.host.messageBox("Initial number of nodes under rootNode: " + xfa.record.nodes.length); // Create a node of blazon dataGroup. var oGroupNode = xfa.datasets.createNode("dataGroup", "NewGroupNode"); // Suspend the data group node to an existing data model node. xfa.record.nodes.append(oGroupNode); // Display the number of child nodes under rootNode. xfa.host.messageBox("Number of nodes under rootNode after first append: " + xfa.record.nodes.length); // Create a node of type dataValue. var oValueNode = xfa.datasets.createNode("dataValue", "NewValueNode"); // Set the value of the new data value node. oValueNode.value = "The item value"; // Suspend the information value node to the information group created in a higher place. xfa.record.NewGroupNode.nodes.append(oValueNode); // Become the value from the data model. TextField1.rawValue = xfa.tape.NewGroupNode.NewValueNode.value; // Append a cloned data group node. xfa.record.nodes.append(xfa.record.NewGroupNode.clone(1)); // Brandish the number of child nodes under rootNode. xfa.host.messageBox("Number of nodes nether rootNode after appending clone: " + xfa.tape.nodes.length); // Prepare the value of the new data value node. xfa.resolveNode("xfa.record.NewGroupNode[1].NewValueNode").value = "The clone value"; // Get the value of the cloned data value node. TextField2.rawValue = xfa.resolveNode("xfa.tape.NewGroupNode[1].NewValueNode").value; // Remove the cloned data group from the node list. var oRemoveNode = xfa.resolveNode("xfa.record.NewGroupNode[1]"); xfa.record.nodes.remove(oRemoveNode); // Display the number of child nodes under rootNode. xfa.host.messageBox("Number of nodes nether rootNode once clone node removed: " + xfa.record.nodes.length); Manipulating instances of a subformThese examples illustrate several ways to add or remove instances of a subform at run time. Use the instance manager to manipulate the pages of a class that has a fixed layout. Each page is a subform; therefore, adding or removing a subform will wait similar adding or removing a page. All the same, at run fourth dimension, you cannot change the layout of a form that has a stock-still layout. Y'all can add and delete instances at the form:ready event; however, if the script is on a run-time event, such equally click, nothing will happen. Uses
ScriptsCalculation an instance past invoking the instance managing director// Add an instance of a subform by using the underscore syntax to invoke the // instance director directly. // Forms rendered in a web browser do non support the underscore syntax. // However, the underscore syntax is supported if the script runs at the // server. _Subform2.addInstance(one); Calculation an instance by invoking the instanceManager property// Add an instance of a subform past invoking the instanceManager holding. Exist // careful to ensure that adding a subform will not violate the max occur // value. Subform2.instanceManager.addInstance(1); Removing an instance// Remove an case of a subform. Set the min occur value simply if removing an // instance volition violate it. For example, fix the min occur to 0 if you lot desire to // remove the last, or the only, instance of a subform. // Forms rendered in a web browser do non support the underscore syntax. // Nonetheless, the underscore syntax is supported if the script runs at the // server. Subform2.occur.min = "0"; _Subform2.removeInstance(0); Removing the parent subform// Remove the parent subform. parent.occur.min = "0"; parent.instanceManager.removeInstance(parent.index); Setting the number of instances// Gear up the number of instances of a subform. var oSubform = xfa.resolveNode("Subform2"); oSubform.instanceManager.setInstances(5); Inserting a new subform instance// Insert a new subform instance. This script will non piece of work with a static class. // The script is invoked by a button, named Insert Subform, that is nested // inside a repeating subform. The new subform is inserted below the current // subform. var oSubform = this.resolveNode("Subform2"); var oNewInstance = oSubform.instanceManager.addInstance(i); var nIndexFrom = oNewInstance.index; var nIndexTo = this.parent.alphabetize + 1; // Invoke the instanceManager to insert the subform below the current one. oSubform.instanceManager.moveInstance(nIndexFrom, nIndexTo); Adding and removing a subform// Invoke the instance director to add and remove the comments subform. if (fComments.value == "0") { // In this example, fComments is a document variable used every bit a flag. // The fComments variable equals 1 when the comments subform is displayed. _comments.setInstance(1); // Add together the comments subform. Change the button's explanation. this.resolveNode("caption.value.#text").value = "Clear Comments"; // Set up the flag value. fComments.value = "one"; } else { // Remove the comments subform. _comments.setInstance(0); // Change the button's caption. this.resolveNode("caption.value.#text").value = "Add Comments"; // Reset the flag value. fComments.value = "0"; } Getting or setting object valuesThese examples illustrate several means to go or fix a value for an object. Uses
ScriptsUsing rawValue// Use the rawValue property to set and get a field'south raw value. TextField1.rawValue = "K1V1W3"; // Fix the field's raw value. TextField2.rawValue = TextField1.rawValue // Get the field'south raw value. Using value// Employ the value property to fix and become the field'due south raw value. TextField1.rawValue = "k1V1W3"; TextField2.rawValue = TextField1.value.oneOfChild.value Using formattedValue// Use the formattedValue property to set and go the field's formatted value. // Use the value property to set and get an object's value (moving-picture show). TextField1.rawValue = "K1V1W3"; // Set the field's raw value. TextField1.format.picture.value = "A9A 9A9"; // Set up the field'due south brandish picture format. TextField2.rawValue = TextField1.formattedValue; // Get the field's formatted value. Setting a data object's value// Utilize the value property to set up and get a data object'south value. // In this script, groupNode is a data group and addressL1 is a data value in // the data file. TextField1.rawValue = xfa.record.groupNode.address.line1.value; Setting the certificate variable'south value// Use the value belongings to set and get the document variable's value. TextField1.rawValue = docVar.value; Working with folio numbers and page countsThese examples illustrate several ways to use the host and layout models to work with page numbers and page counts. The host and layout models accept several different backdrop and methods for working with page numbers and page counts. The properties and methods that you should use depend on what the script does and when it executes. Many of the host backdrop and methods are unavailable on the server. Use the host properties and methods to set or get page numbers at run time. None of the layout methods gear up the page number. Use the layout methods to get the current page at layout:ready or to display the page numbers at the bottom of the folio and run across the folio number when you lot open up a grade on a client. Uses
ScriptsGetting the page number// Utilize the page layout methods to get the current page number. TextField1.rawValue = xfa.layout.page(this); // ane-based. TextField2.rawValue = xfa.layout.absPage(this); // 0-based. Getting the page count using the pageCount method// Use the layout pageCount methods to get the number of pages in a document. TextField1.rawValue = xfa.layout.pageCount(); // Get the logical number of pages. TextField2.rawValue = xfa.layout.absPageCount(); // Get the physical number of pages. Formatting the pagination// Use the layout page and pageCount methods to format the pagination. TextField1.rawValue = "Page " + xfa.layout.folio(this) + " of " + xfa.layout.pageCount(); Getting and setting the current page number// Employ the host currentPage property to get and set the current page number at // run time. // This script cannot exist used during a layout:ready, form:set up, or initialize // event. Even so, it will work if the script is on a button. xfa.host.currentPage = ane; // Go to page 2 (0-based). Getting the folio count using the numPages property// Use the host numPages holding to become the number of pages in a document. TextField1.rawValue = xfa.host.numPages; // Get the number of pages. Navigating down a document// Utilise the host pageDown() method to navigate through a document. xfa.host.pageDown(); // Go to the next page. Navigating up a document// Use the host pageUp() method to navigate through a document. xfa.host.pageUp(); // Go to the previous page. Concatenating data valuesThis example illustrates how to concatenate data values into an address block and ensure that there are no blank lines. Uses
ScriptConcatenating data values// Go the values from the data model. var sName = xfa.record.groupNode.address.line1.value; var sPostbox = xfa.record.groupNode.address.line2.value; var sStreet = xfa.tape.groupNode.accost.line3.value; var sCity = xfa.tape.groupNode.address.line4.value; var sRegion = xfa.record.groupNode.address.line5.value; var sCountry = xfa.record.groupNode.accost.line6.value; var sPostcode = xfa.record.groupNode.address.line7.value; var addressArray = new Array(sName,sPostbox,sStreet,sCity,sRegion,sCountry,sPostcode); var sAddressBlock = ""; // Don't display the postbox if the value is not provided. if (addressArray[1] == null) { sAddressBlock = addressArray[0] + "\n" + addressArray[2] + "\north" + addressArray[3] + "\northward"; } else { sAddressBlock = addressArray[0] + "\n" + addressArray[1] + "\due north" + addressArray[3] + "\north"; } // Do not brandish the region if the value is not provided. if (addressArray[four] == nix) { sAddressBlock = sAddressBlock + addressArray[5] + " " + addressArray[vi]; } else { sAddressBlock = sAddressBlock + addressArray[iv] + ", " + addressArray[5] + " " + addressArray[6]; } TextField2.rawValue = sAddressBlock; // Brand sure the field is set to display a multiple line value. To set up the // multiLine property programmatically, add the following line: TextField2.ui.oneOfChild.multiLine = "one"; Calculating totalsThis example illustrates how to summate totals. Uses
ScriptCalculating totals// Access a field in a repeating subform by looping through the node list. var oFields = xfa.resolveNodes("Subform2[*].NumericField4"); var nNodesLength = oFields.length; var nSum = 0; for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { nSum += oFields.particular(nNodeCount).rawValue; } TextField1.rawValue = nSum; Changing the background colourThese examples illustrate how to change the background color of a subform or fields. In a form that has a flowable layout, you can change the groundwork color of the entire field, including the caption and the field area, at run time. However, in a grade that has a fixed layout, you lot can simply modify the background color of the field area at run time. Uses
ScriptsChanging the background color of a subform// Alternating the groundwork color of a repeating subform. var oNodes = xfa.resolveNodes("Subform2[*]"); var nNodesLength = oNodes.length; for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { if (oNodes.detail(nNodeCount).index%two != 0) { oNodes.item(nNodeCount).edge.fill.color.value = "200,200,250"; } else { oNodes.item(nNodeCount).edge.make full.color.value = "200,150,250"; } } Changing the background color of a field// Alternating the background color of the NumericField4 field. // Before running this script, ready a background color or set the // edge.fill.presence property to visible. var oNodes = xfa.resolveNodes("Subform2[*]"); var nNodesLength = oNodes.length; var sFillColor; for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { if (oNodes.item(nNodeCount).index%2 != 0) { sFillColor = "200,200,250"; } else { sFillColor = "200,150,250"; } oNodes.particular(nNodeCount).NumericField4.fillColor = sFillColor; } Changing the background colour of rows in a subform// Reset the fields of the current subform. var dString = "xfa.form.form1.dtls[" + this.parent.index + "]"; var oDetails = xfa.grade.resolveNode(dString); var sDtlFields; // Build the cord of field names to reset. for (var i = 0; i < oDetails.nodes.length; i++) { sDtlFields = sDtlFields + "," + dString + "." + oDetails.nodes.detail(i).name; } // Pass the string variable equally a parameter. xfa.host.resetData(sDtlFields); OR // Alternate the background color of the repeating rows. if (this.index%ii != 0) this.edge.fill.color.value = "255,255,255"; else this.edge.fill.color.value = "201,201,146"; Populating a drib-downwards listThese examples illustrate several ways to add together or remove list items in a driblet-downwardly listing. Save the item list before you lot populate a drib-downwardly list at run time; otherwise, the items will be lost. Only the value is saved in the data. Uses
ScriptsPopulating a driblet-down listing from a web service// Populate the drop-downwards list with values from a spider web service. // The web service used in this example is fictional. SOAP.wireDump = imitation; var oListURL = "http://www.webservice.net/wsdl/query.wsdl"; var e; try { xfa.host.messageBox("Starting listing retrieval."); var service = Soap.connect(oListURL); if(typeof service != "object") { xfa.host.messageBox("Couldn't get List object."); } if(service.getAllServiceNames == "undefined") { xfa.host.messageBox("Couldn't get getAllServiceNames Call."); } // Start the query var oItems = service.getAllServiceNames(); if(oItems == null) { xfa.host.messageBox("Listing empty."); } var nCount = 0; var nLimit = 10; for(var nItemCount in oItems) { for(var nItemNode in oItems[nItemCount]) { if (nItemNode == "proper name") DropDownList1.addItem(oItems[nItemCount][nItemNode]); } if (++nCount >= nLimit) break; } } catch(e) { xfa.host.messageBox("Problem with listing Phone call: " + e); } Clearing a drop-downwards listing// Clear the items in a drop-down list. DropDownList1.clearItems(); Populating a drop-downwardly list from a data file// Populate the drop-down list with values from a data file. var oItems = xfa.resolveNode("xfa.record.groupNode.listing"); var nItemsLength = oItems.nodes.length; for (var nItemCount = 0; nItemCount < nItemsLength; nItemCount++) { DropDownList1.addItem(oItems.nodes.item(nItemCount).value); } DropDownList1.rawValue = "2d item in list"; Saving the values from a drop-downwards list in another field// Access the items in a driblet-downward list box and salve their values in a carve up // field. var oItems = xfa.resolveNode("DropDownList1.#items"); var nItemsLength = oItems.nodes.length; for (nItemCount = 0; nItemCount < nItemsLength; nItemCount++){ if (TextField2.rawValue == nothing) { TextField2.rawValue = oItems.nodes.detail(nItemCount).value; } else { TextField2.rawValue = TextField2.rawValue + "\north" + oItems.nodes.item(nItemCount).value; } } Accessing a drop-down list value using newText or prevText backdrop// Use the newText or prevText properties to access a drop-downward list value // before or afterwards the value changes. // Execute the script on a change issue. TextField1.rawValue = xfa.event.prevText; TextField2.rawValue = xfa.event.newText; Saving a formThese examples illustrate how to export data from a class and save a form. Uses
ScriptsExporting form information without specifying a file proper noun// Consign a form's data without specifying a file name. The stop user is // prompted to provide the file name. xfa.host.exportData(); // Volition generate data in XDP format. xfa.host.exportData("", 0); // Will generate data in XML format. Exporting form data using a filename// If yous specify a file name, the script must run on a certified form. xfa.host.exportData("filename.xdp"); // Will generate data in XDP format. xfa.host.exportData("filename.xml", 0); // Will generate data in XML format. Saving a class// Saving the form is done at the application level, so you demand to invoke the // Acrobat app model. App.executeMenuItem("SaveAs"); // The end user will be prompted to specify a // file proper noun. // Notwithstanding, you must save the form silently if the form needs to be certified // and the document must be trusted for privileged JavaScript. var mydoc = event.target; mydoc.saveAs(); Making an object visible or invisibleThis example illustrates how to make an object visible or invisible. If a print button is invisible, it volition prevent the user from printing a form. The prePrint event triggers immediately before the class is rendered for printing. Similarly, the postPrint event triggers immediately after the form has been printed. Uses
ScriptsSetting a field to be visible or invisible// If a field is visible, make information technology invisible and vice versa. if(Field1.presence == "visible") { Field1.presence = "invisible"; } else { Field1.presence = "visible"; } Setting a push button to be visible but non-printing// Set a button to be visible simply not-printing at design fourth dimension. Button1.relevant="-print" Using radio buttons and cheque boxesThese examples illustrate how to select and clear radio buttons and check boxes. Uses
ScriptsSelecting a radio button// Select the first radio button. RadioButtonList.rawValue = '1'; xfa.host.messageBox('Value of RadioButtonList: ' + RadioButtonList.rawValue); // Select the second radio push button. RadioButtonList.rawValue = 'two'; xfa.host.messageBox('Value of RadioButtonList: ' + RadioButtonList.rawValue); Accessing radio buttons// Access the radio buttons. RadioButtonList.resolveNodes("#field[*]") Clearing a radio push// Clear a RadioButtonList value. Any invalid value will articulate the list. RadioButtonList.rawValue = '3'; xfa.host.messageBox('Value of RadioButtonList: ' + RadioButtonList.rawValue); Selecting a bank check box// Select a cheque box. CheckBox1.rawValue = 1; xfa.host.messageBox('Value of checkbox: ' + CheckBox1.rawValue); Deselecting a check box// Deselect a cheque box. CheckBox1.rawValue = 0; xfa.host.messageBox('Value of checkbox: ' + CheckBox1.rawValue); Determining that a form has inverseThis instance illustrates how to determine that a form has changed. Uses
ScriptDetermining that a form has changed// Save a copy of the original XML file. var sOriginalXML = xfa.data.saveXML(); // Alter the class data. TextField1.rawValue = "changed"; // Make up one's mind whether the form information has inverse. if(sOriginalXML == xfa.data.saveXML()) { xfa.host.messageBox("Form has not changed."); } else { xfa.host.messageBox("Form has inverse."); } Disabling all class fieldsThis example illustrates how to disable all the fields on a form. Uses
ScriptDisabling all grade fields// Get the field containers from each page. for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) { var oFields = xfa.layout.pageContent(nPageCount, "field"); var nNodesLength = oFields.length; // Set the field property. for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) { oFields.item(nNodeCount).admission = "readOnly"; } } |
Source: https://help.adobe.com/en_US/livecycle/10.0/DesignerScriptingRef/WS92d06802c76abadb-3e14850712a151d270d-7ffa.html

Twitter™ and Facebook posts are not covered under the terms of Creative Commons.
0 Response to "Javascript Cannot Read Property 'showmessagebox' of Undefined"
Post a Comment