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('');

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