heating-calculator-tool

Heating Calculator

Heating Calculator

Tell Us About Your Space

Please note that this a general estimate of what you may need. If you’d like to get a more in‑depth assessment, please get in touch with us!

`; return html; } // --------------------------------- // 7) EVENT LISTENERS // --------------------------------- // Back button backBtn.addEventListener('click', showCalculator); // Send copy button sendCopyBtn.addEventListener('click', async () => { const email = document.getElementById('hc-results-email').value; if (!email) { alert('Please enter your email address'); return; } // Validate email format const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(email)) { alert('Please enter a valid email address'); return; } // Show loading state const button = sendCopyBtn; const originalText = button.textContent; button.textContent = 'Sending...'; button.disabled = true; try { // Get current user inputs and recommendations from the rendered results const userInputs = getCurrentUserInputs(); const recommendations = getCurrentRecommendations(); // Debug logging console.log('Email address:', email); console.log('User inputs:', userInputs); console.log('Recommendations:', recommendations); // Generate HTML email content const emailHtml = generateEmailHTML(userInputs, recommendations); console.log('Generated HTML length:', emailHtml.length); const requestData = { email: email, htmlContent: emailHtml, subject: 'Your Heating Calculator Results - Heating Green' }; console.log('Sending request data:', requestData); const response = await fetch('/wp-json/heating-calculator/v1/send-results', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(requestData) }); const result = await response.json(); if (response.ok && result.success) { alert('Email sent successfully! Check your inbox for your heating calculator results.'); } else { throw new Error(result.message || 'Failed to send email'); } } catch (error) { console.error('Email error:', error); alert('Sorry, there was an error sending your email. Please try again or contact us directly.'); } finally { // Reset button state button.textContent = originalText; button.disabled = false; } }); })();

Shopping Cart