ANS-1350 · SUITESCRIPT DEVELOPMENT

How to Access Form Elements in NetSuite Client Scripts: Understanding DOM Limitations

Learn why direct DOM manipulation for non-form controls like DIVs and SPANs is discouraged in NetSuite, and what alternatives are recommended.

Short answer

When working with form objects in NetSuite client scripts, direct Document Object Model (DOM) manipulation for non-form control elements like DIVs and SPANs is discouraged. The `form.elements` array specifically retrieves only form controls. For accessing and manipulating elements, NetSuite recommends using SuiteScript APIs instead of direct DOM methods.

Scenario

Users attempting to manipulate HTML form objects within NetSuite client scripts may encounter limitations when trying to retrieve all elements. Specifically, non-form control elements such as DIVs and SPANs might not be accessible through methods commonly used for form controls, leading to unexpected behavior or an inability to interact with these elements as intended.

Solution

When manipulating a form object in HTML, attempting to retrieve all elements in the form will only return the form controls. This means that the elements[] array (referring to form.elements) is limited to form input fields, buttons, and other interactive controls. For general HTML elements such as DIVs and SPANs, direct Document Object Model (DOM) manipulation using methods like document.getElementById is strongly discouraged in NetSuite client scripts. NetSuite's current documentation recommends utilizing SuiteScript APIs for interacting with elements to ensure compatibility and maintainability within the platform.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant