How to show a greeting based on the time of day
This little JS snippet, when used on your form, will record a message based on the current time of day. The message, recorded to a hidden field on the form can be used on the form to show a friendly greeting "Good Afternoon!" or used on an email.
Just add a field to your form named 'greeting' and then use a Custom JavaScript Form Action with the following code:
// This function will receive the field and form objects.
function(field,form){
var d = new Date();
var time = d.getHours();
var greeting = undefined;
if (time < 12) {
greeting = "Good Morning!"
}
if (time === 12) {
greeting = "Good Noon!"
}
if(time > 12){
greeting = "Good Afternoon!"
}
if (time > 18) {
greeting = "Good Evening!"
}
form.getFieldByName("greeting").setValue(greeting)
}
The code will populate the field [greeting] with a greeting message based on their computer's time.
Have more questions? Submit a request
-
Clinton Tu Cool!
Please sign in to leave a comment.
1 Comments