Press "Enter" to skip to content

How to find a control instance with JavaScript


In the current article I would like to share a number of ways, how to find a control instance with JavaScript in K2 Smartforms. Please, note, that this is not supported and might now work as expected in different K2 Versions. Moreover, this is not something you need on a daily basis, but rather rarely for certain functionality, that is not available out of the box. When you need to inject something and need to set or get the value of a control.

This article involves the usage of JavaScript on the form. If something is not clear, please, read the article How to add JavaScript on Smartforms.

A bit of information about a control ID

Uniqueness of a control object is secured via their IDs. Usually, the control ID consists of a GUID of the view instance, placed on the form, and a control ID. If the control is placed directly on the form, the first GUID is replaced with 00000000-0000-0000-0000-000000000000.

i.e. ViewInstanceGUID_ControlGUID
Example of a View control ID:
Example of a Form control ID:

However, for certain controls, like e.g. Text Area, additional suffixes are added.

Example of a Text Area ID:

I am trying to point out, that there is no generic way to get the control object. Therefore, below I am giving some cases, which are the most frequent.

Finding most of the controls

The first way is suitable for the controls, that have a name attribute in Html. These are the following controls:

  • Label
  • Content
  • Autocomplete
  • Data Label
  • Choice
  • List Box
  • Multi-Select
  • Rich Text
  • Slider
  • Text Box
  • Button

The next approach is suitable for controls, that do not have the Name property in Html.



Check Box

Check Box List & Radio Button List

Drop-Down List



Radio Button

Text Area

Toolbar Button

These are the most frequent types of controls, that users try to find in K2. After you were able to find a control with JavaScript, you can now get and set values or do something else. I will describe that in one of the next posts.

Leave a Reply

Your email address will not be published. Required fields are marked *

9 + 15 =