Common Patterns
Forsta HX Platform - API Scripting Guide
Common Patterns
Access DOM Elements (jQuery):
// Find inputs within a question
var radios = f('AQ1').find('input[type="radio"]');
var checks = f('BQ2').find('input[type="checkbox"]');
// Get selected checkbox/radio
var checked = f('CQ3').find('input:checked');
// Get labels of selected options
var labels = f('DQ4').find('input:checked').map(function() {
return $(this).next('label').text();
}).get();
Loop Through Selected Options (Forsta API - Recommended):
// Use Forsta API to loop through all options
var codes = f('AQ1').domainValues();
codes.forEach(function(code) {
if (f('AQ1').item(code).toBoolean()) {
console.log('Selected: ' + code);
console.log('Value: ' + f('AQ1').item(code).toNumber());
}
});