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.





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')
// you can use the setValue function to clear the checkbox:

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