Lua Scripting Resources
Important Update to Custom Scripting
SurveyGizmo's CustomScript Action now supports the LUA programming language.
Legacy Custom Scripting Language Deprecation Plans
New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
In the long term, Legacy Custom Scripting Actions will be switched to read-only. Read-only scripts will continue to function; you will just be prevented from editing. The exact date on this is to be determined; we will send notifications well ahead of time.
Go to our Legacy Scripting Documentation .
While SurveyGizmo is one of the most flexible survey tools around, we get requests for customizations that are not available out of the box. This is where JavaScript and Custom Scripting can save the day. If you have scripting chops you can use the JavaScript action or the Custom Scripting action to achieve the survey of your dreams.
[article("bodfy")]
This JavaScript will calculate age from the date of birth entered in an open-text field.
See this script in action in an example survey . OR
Add a survey with this script and setup to your account!The Setup and Script First, add your date of birth Date question. Go to the Layout tab of your date of birth question and add the following to the CSS Class Name field :Enter dob if you are using the DD/MM/YYYY format Enter dob2 if you are using the MM/DD/YYYY format Next, add a field to store your calculated age. This can be a Textbox or a Hidden Value. On the Layout tab of your field that stores age add the following to the CSS Class Name field:Enter age if you are using the DD/MM/YYYY format Enter age2 if you are using the MM/DD/YYYY format Next, add a Javascript action to the same page and add one of the below JavaScript code snippets. If your DOB question is in MM/DD/YYYY format copy and paste this Javascript:
//calculate age from MM/DD/YYYY formatted date question
//add CSS class "dob2" to date question, "age2" to textbox to store the age
$(document).ready(function() {
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
if (isMobile.any()) {
// It is mobile
function calculateAge(birthday) {
var ageDifMs = Date.now() - birthday.getTime();
var ageDate = new Date(ageDifMs);
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
$(".dob2 :input").change(function() {
var birthday = $(this).val();
birthday = birthday.split("/");
birthday = new Date(birthday[2], birthday[0] - 1, birthday[1]);
var age = calculateAge(birthday);
$(".age2 :text").val(age);
});
} else {
function calculateAge(birthday) {
var ageDifMs = Date.now() - birthday.getTime();
var ageDate = new Date(ageDifMs);
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
$(".dob2 :text").change(function() {
var birthday = $(this).val();
birthday = new Date(birthday);
var age = calculateAge(birthday);
$(".age2 :text").val(age);
});
}
}); If your DOB question is in DD/MM/YYYY format copy and paste this Javascript:
//calculate age from DD/MM/YYYY formatted date question
//add CSS class "dob" to date question, "age" to textbox to store the age
$(document).ready(function() {
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
if (isMobile.any()) {
// It is mobile
function calculateAge(birthday) {
var ageDifMs = Date.now() - birthday.getTime();
var ageDate = new Date(ageDifMs);
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
$(".dob :input").change(function() {
var birthday = $(this).val();
birthday = birthday.split("/");
birthday = new Date(birthday[2], birthday[0], birthday[1] - 1);
var age = calculateAge(birthday);
$(".age :text").val(age);
});
}
else {
function calculateAge(birthday) {
var ageDifMs = Date.now() - birthday.getTime();
var ageDate = new Date(ageDifMs);
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
$(".dob :text").change(function(){
var birthday = $(this).val();
birthday = birthday.split("/");
birthday = new Date(birthday[2], birthday[1] - 1), birthday[0];
var age = calculateAge(birthday);
$(".age :text").val(age);
});
}
});