Please enable JavaScript to view this site.

Navigation: Advanced topics > Programming topics > JavaScript API > Control object > Methods

JavaScript API: Control object > setValue()

Scroll Prev Next More

 

Sets the control value.

Syntax

ctrl.setValue(value);

Arguments

value

the value of the control.

Return value

No return value.

Example 1

Calculate the total value on the fly using the JavaScript OnLoad event:

 

var ctrlPrice = Runner.getControl(pageid, 'Price');
var ctrlQuantity = Runner.getControl(pageid, 'Quantity');
var ctrlTotal = Runner.getControl(pageid, 'Total');
 
function func() {
 ctrlTotal.setValue(Number(ctrlPrice.getValue()) * Number(ctrlQuantity.getValue()));
};
 
ctrlPrice.on('keyup', func);
ctrlQuantity.on('keyup', func);

Example 2

Show an alert if the checkbox control is checked using the JavaScript OnLoad event:

 

var ctrl = Runner.getControl(pageid, 'Discounted');
if (ctrl.getValue()=='on')
  alert('Checked');
 
// you can use the setValue function to clear the checkbox:
ctrl.setValue('');

Example 3

Select multiple values in a multi-select control.To make this happen we need to pass a Javascript array as an argument.

 

var ctrl = Runner.getControl(pageid, 'Options');
ctrl.setValue( [1,10,12] );

 
// and here is the syntax for passing text values
// ctrl.setValues( ['apple', 'orange', 'banana'] );

See also:

JavaScript API: Control object > getControl()

JavaScript API: Control object > getValue()

JavaScript API: Control object > on()

Example: Show dropdown list of US states if US was selected in country list

Events: JavaScript OnLoad

JavaScript API: Control object

JavaScript API

 

Created with Help+Manual 7 and styled with Premium Pack Version 3 © by EC Software