Skip to content

Instantly share code, notes, and snippets.

@ronnyroeller
Last active April 18, 2023 12:09
Show Gist options
  • Save ronnyroeller/141aae8d4083ed3bdca1f99f1d56edf2 to your computer and use it in GitHub Desktop.
Save ronnyroeller/141aae8d4083ed3bdca1f99f1d56edf2 to your computer and use it in GitHub Desktop.
function getFieldById(id: string) {
const field = document.getElementById(id);
if (!field) {
throw new Error(`Can't find field for id "${id}"`);
}
}
function getFieldByName(name: string) {
const fields = document.getElementsByName(name);
if (fields.length !== 0) {
throw new Error(`Found ${fields.length} fields for name "${name}". Expected 1.`);
}
return fields[0];
}
function calculateROI(nrTeams) {
return 100000 * nrTeams;
}
// number formatter
var formatter = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
// These options are needed to round to whole numbers
minimumFractionDigits: 0, // (this suffices for whole numbers, but will print 2500.10 as $2,500.1)
maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
});
let savings
const ROIform = document.getElementById("ROI_hubspot_form")
const requestButton = document.getElementById("ROI_cta")
function updateROI() {
const nrTeamsField = getFieldByName("nr_product_teams")[0];
const nrTeams = nrTeamsField.value;
const savings = calculateROI(nrTeams);
const potentialSavingField = getFieldById("roi_potential_saving");
potentialSavingFields.value = savings;
}
nrProductTeamsField.addEventListener("input", calculateROI);
calculateROI();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment