JavaScript Functions for Typical Form Field Tasks
The new JavaScript API not only enables programmatic access to all elements of a document, but also provides events for user interaction.

Version X18 (28.0) is shipped with a complete new JavaScript API to program the online document editor that comes with TX Text Control .NET Server.
The complete JavaScript API documentation can be found in our online docs:
This article describes typical tasks for inserting and processing form fields such as check boxes, drop-down boxes and form text fields.
Adding Form Text Fields
Form text fields can be used to retrieve textual content from users. A form text field has a default empty width (first parameter in the add
function addTextFormField() {
TXTextControl.formFields.getCanAdd(canAdd => {
if (canAdd) {
TXTextControl.formFields.addTextFormField(0, function(insertedFormField) {
insertedFormField.setName("Field1");
});
} else {
alert("Form field cannot be added at this location.");
}
});
}
The get
Get Form Field By Name
While the get
The following asynchronous function loops through all form fields and checks for the name property. If found, the Promise is resolved by returning the form field itself.
function getFormFieldByName(name) {
return new Promise(resolve => {
TXTextControl.formFields.forEach(function(formField) {
formField.getName(function(formFieldName){
if (formFieldName === name)
{
resolve(formField);
}
})
})
});
}
var formField = await getFormFieldByName("Field1");
This function needs to be called from an async function with the await operator to wait for the response.
Inserting Check Form Fields
Analogically with form text fields, check boxes can be added using the add
function addCheckFormField() {
TXTextControl.formFields.getCanAdd(canAdd => {
if (canAdd) {
TXTextControl.formFields.addCheckFormField(true);
}
});
}
Getting Form Fields at the Input Position
In order to get the field at the current input position, the get
function textFieldEnteredHandler(enteredField) {
if (enteredField.textField.type === "CHECKFORMFIELD")
{
TXTextControl.formFields.getItem(function(checkFormField) {
checkFormField.getChecked(function(checked) {
checkFormField.setChecked(!checked);
})
})
}
}
TXTextControl.addEventListener("textFieldEntered", textFieldEnteredHandler);
Adding Selection Form Fields
The following code shows how to insert a non-editable selection form field with pre-defined items. The set
function addDropDownFormField(items) {
TXTextControl.formFields.getCanAdd(canAdd => {
if (canAdd) {
TXTextControl.formFields.addSelectionFormField(0, sff => {
// no custom text
sff.setEditable(false);
sff.setItems(items);
// select "Uber"
sff.setSelectedIndex(3);
});
}
});
}
var transportation = ["Bicycle", "Car", "Scooter", "Uber", "Cab"];
addDropDownFormField(transportation);
Test this on your own using all document editor versions including Angular, Node.js, MVC and Web Forms that all share the same JavaScript API.
Also See
This post references the following in the documentation:
- Javascript: Collection.for
Each Method - Javascript: Form
Field Collection.add Check Form Field Method - Javascript: Form
Field Collection.add Text Form Field Method - Javascript: Form
Field Collection.get Item Method - Javascript: Selection
Form Field.set Selected Index Method - Javascript: Text
Field Object - Javascript: Text
Field.set Name Method - Javascript: Text
Field Collection Base.get Can Add Method - Javascript: TXText
Control. Text Field.name Property
Angular
Integrate document processing, editing, sharing, collaboration, creation, electronic signatures, and PDF generation into your Angular Web applications.
Related Posts
Observe When the Reporting Preview Tab is Active Using MutationObserver
This article shows how to observe when the Reporting Preview tab is active using MutationObserver. The Reporting Preview tab is a feature of the TX Text Control Document Editor that allows you to…
Building an ASP.NET Core Backend Application to Host the Document Editor and…
This article explains how to create an ASP.NET Core backend application to host the Document Editor and Document Viewer. This backend application is required to provide the required functionality…
Building an ASP.NET Core Backend (Linux and Windows) for the Document Editor…
This article shows how to create a backend for the Document Editor and Viewer using ASP.NET Core. The backend can be hosted on Windows and Linux and can be used in Blazor, Angular, JavaScript, and…
AngularJavaScriptDocument Editor
Getting Started: Document Editor Version 33.0 with Angular CLI 19.0
This article shows how to use the TX Text Control Document Editor version 33.0 npm package for Angular within an Angular CLI 19.0 application. It uses the trial backend running on our servers, but…
Using the Document Editor in SPA Applications using the removeFromDom Method
This article shows how to use the removeFromDom method to remove the Document Editor from the DOM when it is no longer needed. This is useful when the Document Editor is used in a Single Page…