Please enable JavaScript to view this site.

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

JavaScript API: Date Control API > setValue()

Scroll Prev Next More

 

This method sets the Date control value.

Syntax

ctrl.setValue(value)

Arguments

value

a datetime string "2001-05-12 12:22:33", a JavaScript Date or a Moment.js object.

Return value

No return value.

Examples

setValue() can be used in the JavaScript OnLoad event, as well as any other JavaScript event.

 

1. Set the date control value to 12/24/19 as a string date.

 

//string date
var ctrl = Runner.getControl(pageid, 'datefield');
ctrl.setValue('2019-12-24 12:15:30');

 

2. Set the date control value as a JavaScript Date object.

 

//javascript date object
var ctrl = Runner.getControl(pageid, 'datefield');
var js_date = new Date('2019-12-24T03:24:00');
ctrl.setValue(js_date);

 

3. Set the date control value as a current date with a Moment.js object.

 

//Moment.js date object
var ctrl = Runner.getControl(pageid, 'datefield');
var moment_date = moment();
ctrl.setValue(moment_date);

 

Note: replace "datefield" with the actual field name in the function.

See also:

JavaScript API: Control object > getControl()

JavaScript API: Date Control API > getValue()

JavaScript API: Date Control API > getMomentValue()

Events: JavaScript OnLoad

Event editor

Date control API

JavaScript API

 

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