View Categories

Using components in view scripts

You can easily use the List box, combo box and text box in view scripts.

We will start with a simple example showing how to use the combo box programmatically:

1. We will create the combo box and add it to the view.

2. We will create a button next to the combo box, on its press we will call view script function get Item.

getitem

onclick

3. In getItem fuction, we will get value of selected component

var selItem = myscada.getSelectedItem('Comp29328366');

‚Comp29328366‘ is an ID of our Combo box. You can find ID in properties window upon clicking on your Combo box.

Once we get the selected item, we will show it by calling alert(selItem);

8.3.3

4. Now we will create a new button. On its press we will call view script function setItem where we will set item in combo box to second item.

8.3.4

Callback function example: #

If you want to be notified, when user selects an item in the combo box or list box, or presses and enters into the text box, set up a callback function.

1. Define your callback function in View Script

8.3.5

As you can see, into your callback function, you will get 2 arguments, first is a selected item and second is an index of the selected item.

2. Click on your component in view and fill in the callback function name

8.3.6

3. When user selects an item, your callback function will be called

8.3.7

Setting new values into Components Programmatically #

You can easily change the items in your component programmatically. To do so, you can use function setItems:

var items = ['item 1','item 2'];
myscada.setItems('id',items);

Coloring items in List Box #

List box allow you to fine tune appearance of each item by specifying the colors and bold face of the font. To do so, use function setItems. Passed items in array will not be strings but objects with additional properties. Simple Example:

8.3.8

Will produce following output

output