document.addEventListener("DOMContentLoaded", function(){
function getFieldValue(form, fieldId, fallback) {
const field = form.querySelector('[name="form_fields[' + fieldId + ']"]');
const value = field ? parseFloat(field.value) : NaN;
return isNaN(value) ? fallback : value;
}
function setFieldValue(form, fieldId, value) {
const field = form.querySelector('[name="form_fields[' + fieldId + ']"]');
if (field) {
field.value = value;
}
}
function calculateROI(form) {
let pressCost = getFieldValue(form, 'makeready_cost', 1250);
let jobs = getFieldValue(form, 'jobs', 6);
let pressLoss = pressCost * jobs;
let totalDaily = pressLoss;
let totalMonthly = totalDaily * 22;
let estimatedSavings = totalMonthly * 0.4;
let roundedMonthly = Math.round(totalMonthly);
let roundedSavings = Math.round(estimatedSavings);
const roiResult = document.getElementById('roiResult');
const roiMain = document.getElementById('roiMain');
const roiSub = document.getElementById('roiSub');
const roiLeadMessage = document.getElementById('roiLeadMessage');
if (roiResult) {
roiResult.style.opacity = 1;
}
if (roiMain) {
roiMain.innerHTML =
"You could save approx. $" + roundedSavings.toLocaleString() + " / month";
}
if (roiSub) {
roiSub.innerHTML =
"Your monthly Make Ready cost is $" + roundedMonthly.toLocaleString() + ". Most flexo printers reduce this by 30-50% with ChromaQA and SmartInk. You could recover approx. $" +
roundedSavings.toLocaleString() +
" / month.";
}
if (roiLeadMessage) {
roiLeadMessage.innerHTML =
"You could recover approx. $" +
roundedSavings.toLocaleString() +
" / month. Enter your email for a personalized analysis by one of our color experts.";
}
/*
Optional hidden fields.
Add these to your Elementor form if you want the calculated values in the email:
monthly_waste
estimated_savings
*/
setFieldValue(form, 'monthly_waste', roundedMonthly);
setFieldValue(form, 'estimated_savings', roundedSavings);
}
/*
Run calculation when the form submits.
Important: we do NOT use e.preventDefault().
Elementor must be allowed to submit the form so the email action works.
*/
document.addEventListener('submit', function(e) {
if (!e.target.classList.contains('elementor-form')) return;
calculateROI(e.target);
}, true);
});