Skip to main content
Participating Frequently
January 30, 2024
Answered

Time Dropdown list from script

  • January 30, 2024
  • 1 reply
  • 1490 views

I need to make a dropdown list with times at 15 minute intervals.

I have a script that I got from another post on here but I don't know where to put it in the dropdown properties to make the drop down list.

 

Here is the script I found on here:

var times = [];
for (var i=0; i<=11; i++) {
	for (var j=0; j<=45; j+=15) {
		var hour = (i<10) ? "0"+i : i;
		var minute = (j<10) ? "0"+j : j;
		times.push(hour + ":" + minute + " am")
	}
}
for (var j=0; j<=45; j+=15) {
	var hour = "12";
	var minute = (j<10) ? "0"+j : j;
	times.push(hour + ":" + minute + " pm")
}
for (var i=1; i<=11; i++) {
	for (var j=0; j<=45; j+=15) {
		var hour = (i<10) ? "0"+i : i;
		var minute = (j<10) ? "0"+j : j;
		times.push(hour + ":" + minute + " pm")
	}
}
this.getField("Time").setItems(times);

 

This topic has been closed for replies.
Correct answer try67

I made sure I have a field with the same name as in the getField function and now I get the error: ReferenceError: times is not defined


You must select (highlight) the full code before executing it.

1 reply

try67
Community Expert
Community Expert
January 30, 2024

Just run it from the JS Console. It only needs to run once, and doesn't need to be a part of the file or field itself.

Participating Frequently
January 30, 2024

Thank You!