Nps Survey Calculator

NPS Survey Calculator: Measure Customer Loyalty & Satisfaction :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ccc; –card-background: #fff; –error-color: #dc3545; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; margin: 0; padding: 0; } .container { max-width: 960px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } h1, h2, h3 { color: var(–primary-color); text-align: center; margin-bottom: 20px; } h1 { font-size: 2.5em; } h2 { font-size: 1.8em; margin-top: 30px; border-bottom: 2px solid var(–primary-color); padding-bottom: 10px; } h3 { font-size: 1.4em; margin-top: 25px; color: var(–primary-color); } .calculator-section { background-color: var(–card-background); padding: 30px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); margin-bottom: 30px; } .loan-calc-container { display: flex; flex-direction: column; gap: 20px; } .input-group { display: flex; flex-direction: column; gap: 8px; } .input-group label { font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group select { padding: 12px; border: 1px solid var(–border-color); border-radius: 5px; font-size: 1em; box-sizing: border-box; } .input-group input[type="number"]:focus, .input-group select:focus { outline: none; border-color: var(–primary-color); box-shadow: 0 0 0 3px rgba(0, 74, 153, 0.2); } .input-group .helper-text { font-size: 0.85em; color: #666; } .error-message { color: var(–error-color); font-size: 0.85em; margin-top: 5px; min-height: 1.2em; /* Prevent layout shift */ } .button-group { display: flex; gap: 15px; margin-top: 25px; justify-content: center; flex-wrap: wrap; } button { padding: 12px 25px; border: none; border-radius: 5px; font-size: 1em; font-weight: bold; cursor: pointer; transition: background-color 0.3s ease, transform 0.2s ease; color: white; } button.primary { background-color: var(–primary-color); } button.primary:hover { background-color: #003366; transform: translateY(-2px); } button.success { background-color: var(–success-color); } button.success:hover { background-color: #218838; transform: translateY(-2px); } button.reset { background-color: #6c757d; } button.reset:hover { background-color: #5a6268; transform: translateY(-2px); } button.copy { background-color: #17a2b8; } button.copy:hover { background-color: #117a8b; transform: translateY(-2px); } #results { margin-top: 30px; padding: 25px; background-color: var(–primary-color); color: white; border-radius: 8px; text-align: center; box-shadow: 0 4px 15px rgba(0, 74, 153, 0.3); } #results h3 { color: white; margin-bottom: 15px; } #results .main-result { font-size: 2.5em; font-weight: bold; margin-bottom: 10px; } #results .result-label { font-size: 1.1em; margin-bottom: 20px; opacity: 0.9; } #results .intermediate-results div { margin-bottom: 10px; font-size: 1.1em; } #results .intermediate-results span { font-weight: bold; } .formula-explanation { margin-top: 20px; font-size: 0.95em; color: #555; text-align: center; border-top: 1px dashed #ccc; padding-top: 15px; } table { width: 100%; border-collapse: collapse; margin-top: 25px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05); } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; } thead { background-color: var(–primary-color); color: white; } th { font-weight: bold; } tbody tr:nth-child(even) { background-color: #f2f2f2; } caption { font-size: 1.1em; font-weight: bold; color: var(–primary-color); margin-bottom: 10px; text-align: left; } .chart-container { width: 100%; max-width: 600px; margin: 30px auto; text-align: center; } canvas { border: 1px solid var(–border-color); border-radius: 5px; background-color: var(–card-background); } .chart-legend { margin-top: 15px; display: flex; justify-content: center; gap: 20px; flex-wrap: wrap; } .chart-legend-item { display: flex; align-items: center; font-size: 0.95em; } .legend-color-box { width: 15px; height: 15px; margin-right: 8px; border-radius: 3px; display: inline-block; } .article-content { margin-top: 40px; background-color: var(–card-background); padding: 30px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } .article-content p, .article-content ul, .article-content ol { margin-bottom: 15px; } .article-content li { margin-bottom: 8px; } .article-content a { color: var(–primary-color); text-decoration: none; } .article-content a:hover { text-decoration: underline; } .faq-item { margin-bottom: 15px; border-bottom: 1px dashed #eee; padding-bottom: 10px; } .faq-item:last-child { border-bottom: none; } .faq-question { font-weight: bold; color: var(–primary-color); cursor: pointer; display: flex; justify-content: space-between; align-items: center; } .faq-question::after { content: '+'; font-size: 1.2em; transition: transform 0.3s ease; } .faq-question.active::after { transform: rotate(45deg); } .faq-answer { display: none; margin-top: 10px; padding-left: 15px; font-size: 0.95em; color: #555; } .related-tools ul { list-style: none; padding: 0; } .related-tools li { margin-bottom: 15px; padding: 10px; border: 1px solid #eee; border-radius: 5px; background-color: #fdfdfd; } .related-tools a { font-weight: bold; display: block; margin-bottom: 5px; } .related-tools p { font-size: 0.9em; color: #666; margin-bottom: 0; } .variable-table table { margin-top: 15px; box-shadow: none; } .variable-table th, .variable-table td { border: 1px solid #ddd; } .variable-table th { background-color: #f8f9fa; color: var(–text-color); } .variable-table caption { background-color: transparent; color: var(–text-color); font-weight: normal; text-align: center; margin-bottom: 10px; } .highlighted-result { background-color: var(–success-color); color: white; padding: 15px; border-radius: 5px; font-size: 1.2em; font-weight: bold; text-align: center; margin-top: 15px; margin-bottom: 15px; box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3); } .copy-feedback { font-size: 0.85em; color: var(–success-color); margin-top: 10px; display: none; /* Hidden by default */ } @media (min-width: 768px) { .container { margin: 40px auto; padding: 30px; } h1 { font-size: 3em; } h2 { font-size: 2em; } h3 { font-size: 1.6em; } .button-group { justify-content: flex-start; } }

NPS Survey Calculator: Measure Customer Loyalty & Satisfaction

Calculate your Net Promoter Score (NPS) instantly to gauge customer loyalty and drive business growth.

NPS Calculator

Enter the total number of customers who completed the survey.
Enter the count of customers who gave a score of 9 or 10.
Enter the count of customers who gave a score of 7 or 8.
Enter the count of customers who gave a score of 0 to 6.

Your NPS Results

Net Promoter Score
Promoters: –%
Passives: –%
Detractors: –%
Total Responses Used: —
Results copied successfully!
Formula: NPS = (% Promoters – % Detractors)
Where % Promoters = (Number of Promoters / Total Responses) * 100
And % Detractors = (Number of Detractors / Total Responses) * 100

What is an NPS Survey Calculator?

An NPS survey calculator is a tool designed to quickly and accurately compute your Net Promoter Score (NPS) based on the responses from your customer surveys. The Net Promoter Score is a widely adopted metric for gauging customer loyalty and satisfaction. It's derived from a single question: "On a scale of 0 to 10, how likely are you to recommend [your company/product/service] to a friend or colleague?"

This NPS survey calculator simplifies the process of analyzing survey data. Instead of manually calculating percentages and the final score, you input the counts of different customer response categories (Promoters, Passives, and Detractors), and the calculator provides the NPS score, along with the percentage breakdown of each group.

Who should use it? Any business that collects customer feedback, regardless of size or industry, can benefit from using an NPS survey calculator. This includes:

  • E-commerce businesses
  • SaaS companies
  • Retailers
  • Service providers (e.g., hospitality, finance, healthcare)
  • Product manufacturers

It's particularly useful for customer success teams, marketing departments, product managers, and leadership looking to understand customer sentiment and identify areas for improvement.

Common Misconceptions about NPS:

  • NPS is the only metric that matters: While powerful, NPS should be used alongside other customer feedback metrics for a holistic view.
  • A high NPS guarantees success: A high score is a good indicator, but it needs to be backed by consistent product/service quality and customer experience.
  • NPS is a vanity metric: If not acted upon, NPS can become a vanity metric. The real value lies in understanding the 'why' behind the scores and implementing changes.
  • The score is absolute: NPS scores vary by industry. Benchmarking against industry averages is crucial for context.

NPS Survey Calculator Formula and Mathematical Explanation

The Net Promoter Score (NPS) is calculated using a straightforward formula that relies on categorizing customer responses into three groups: Promoters, Passives, and Detractors. Our NPS survey calculator automates this process.

The Core Formula:

NPS = % Promoters - % Detractors

Step-by-Step Derivation:

  1. Categorize Responses: Customers are grouped based on their score (0-10):
    • Promoters: Score 9 or 10. These are loyal enthusiasts who will keep buying and refer others, fueling growth.
    • Passives: Score 7 or 8. These are satisfied but unenthusiastic customers who are vulnerable to competitive offerings.
    • Detractors: Score 0 to 6. These are unhappy customers who can damage your brand and impede growth through negative word-of-mouth.
  2. Calculate Percentage of Promoters: Divide the number of promoters by the total number of survey responses and multiply by 100.
    % Promoters = (Number of Promoters / Total Responses) * 100
  3. Calculate Percentage of Detractors: Divide the number of detractors by the total number of survey responses and multiply by 100.
    % Detractors = (Number of Detractors / Total Responses) * 100
  4. Calculate NPS: Subtract the percentage of detractors from the percentage of promoters. The resulting score can range from -100 to +100.

Note: The percentage of Passives is calculated similarly (% Passives = (Number of Passives / Total Responses) * 100) but is not directly used in the NPS calculation itself, though it provides valuable context about your customer base.

NPS Calculation Variables
Variable Meaning Unit Typical Range
Total Responses The total number of customers who completed the NPS survey. Count ≥ 0
Promoters Customers who gave a score of 9 or 10. Count ≥ 0
Passives Customers who gave a score of 7 or 8. Count ≥ 0
Detractors Customers who gave a score of 0 to 6. Count ≥ 0
% Promoters The proportion of respondents who are promoters. Percentage (%) 0% – 100%
% Detractors The proportion of respondents who are detractors. Percentage (%) 0% – 100%
NPS Net Promoter Score, indicating overall customer loyalty. Score -100 to +100

Practical Examples (Real-World Use Cases)

Example 1: A Growing SaaS Company

"Innovate Solutions," a software-as-a-service provider, recently sent out an NPS survey to its user base. They received 1,500 responses.

  • Total Responses: 1,500
  • Promoters (Score 9-10): 800
  • Passives (Score 7-8): 450
  • Detractors (Score 0-6): 250

Using the NPS survey calculator:

  • % Promoters = (800 / 1,500) * 100 = 53.33%
  • % Detractors = (250 / 1,500) * 100 = 16.67%
  • NPS = 53.33% – 16.67% = 36.66

Interpretation: Innovate Solutions has an NPS of approximately 37. This is a solid score, indicating more promoters than detractors. However, the significant number of passives (30%) suggests an opportunity to convert them into promoters by enhancing the user experience or offering more value. They should investigate the reasons behind the detractor scores to address critical issues.

Example 2: A Local Restaurant Chain

"Gourmet Bites," a popular restaurant chain, conducted an NPS survey after a recent menu update. They collected 500 responses.

  • Total Responses: 500
  • Promoters (Score 9-10): 150
  • Passives (Score 7-8): 200
  • Detractors (Score 0-6): 150

Using the NPS survey calculator:

  • % Promoters = (150 / 500) * 100 = 30%
  • % Detractors = (150 / 500) * 100 = 30%
  • NPS = 30% – 30% = 0

Interpretation: Gourmet Bites has an NPS of 0. This score suggests a neutral customer sentiment, with an equal number of promoters and detractors. The high percentage of passives (40%) is also a concern. The restaurant needs to focus on improving the dining experience, food quality, and service to reduce detractors and convert passives. Analyzing feedback from detractors is crucial to identify specific pain points. This NPS survey calculator can help them track improvements over time.

How to Use This NPS Survey Calculator

Using our NPS survey calculator is simple and efficient. Follow these steps to get your Net Promoter Score:

  1. Gather Your Data: Collect the results from your customer feedback survey. You need three key numbers:
    • The total number of customers who responded to the NPS question.
    • The number of customers who gave a score of 9 or 10 (Promoters).
    • The number of customers who gave a score of 0 to 6 (Detractors).
    • (Optional but recommended) The number of customers who gave a score of 7 or 8 (Passives).
  2. Input the Numbers: Enter the collected counts into the corresponding fields in the calculator: "Total Survey Responses," "Number of Promoters," and "Number of Detractors." The "Number of Passives" field is optional for the calculation but good for context.
  3. Calculate: Click the "Calculate NPS" button. The calculator will instantly process your inputs.
  4. Review the Results: The calculator will display:
    • Your NPS Score: The primary result, ranging from -100 to +100.
    • Percentage Breakdown: The percentage of Promoters, Passives, and Detractors among your respondents.
    • Total Responses Used: Confirms the total number of responses factored into the calculation.
    • NPS Category: A brief interpretation of your score (e.g., "Excellent," "Good," "Needs Improvement").
  5. Understand the Formula: A clear explanation of the NPS formula is provided below the results for your reference.
  6. Reset or Copy: Use the "Reset" button to clear the fields and start over. Use the "Copy Results" button to copy the key metrics and assumptions for use in reports or other documents.

How to Read Results:

  • NPS > 50: Generally considered excellent.
  • NPS 30-50: Considered good, indicating strong customer loyalty.
  • NPS 10-30: Considered fair; there's room for improvement.
  • NPS < 10: Often considered poor; significant improvements are needed.
  • NPS < 0: Indicates more detractors than promoters, requiring urgent attention.

Remember to compare your NPS score to industry benchmarks for a more accurate assessment of your performance. This NPS survey calculator is a great starting point for tracking your progress.

Decision-Making Guidance:

  • High NPS: Leverage your promoters for testimonials, case studies, and referrals. Continue to nurture these relationships.
  • Moderate NPS: Focus on understanding why customers are passive. Identify opportunities to enhance their experience and encourage advocacy.
  • Low NPS: Prioritize addressing the root causes of dissatisfaction among detractors. Actively solicit feedback from this group to pinpoint specific issues with your product, service, or customer support. Implementing changes based on this feedback is crucial.

Key Factors That Affect NPS Results

While the NPS survey calculator provides a clear score, several underlying factors significantly influence the results. Understanding these can help you interpret your NPS and strategize for improvement:

  1. Product/Service Quality: The fundamental quality, reliability, and performance of your offering are paramount. A superior product naturally leads to more promoters. Conversely, bugs, poor performance, or unmet expectations drive detractors.
  2. Customer Service Experience: Every interaction a customer has with your support team—whether it's resolving an issue, answering a question, or providing onboarding—shapes their perception. Excellent, empathetic, and efficient support can turn a negative situation into a positive one, potentially creating promoters even from detractors. Poor service is a major driver of negative scores.
  3. User Experience (UX) & Ease of Use: For digital products or services, how intuitive and easy it is to use the platform or service is critical. A confusing interface or a cumbersome process can frustrate users, leading to lower scores. A seamless UX fosters satisfaction and loyalty.
  4. Value for Money: Customers assess whether the benefits they receive align with the price they pay. If your offering is perceived as expensive for its value, it can lead to dissatisfaction. Demonstrating clear value and competitive pricing is key to maintaining positive sentiment.
  5. Brand Reputation and Trust: A company's overall reputation, ethical practices, and the trust customers place in it play a significant role. Positive brand perception can influence responses, while negative publicity or a lack of transparency can damage NPS. Building and maintaining trust is an ongoing effort.
  6. Communication and Engagement: How effectively you communicate with your customers—through updates, marketing, and personalized outreach—impacts their relationship with your brand. Proactive communication and feeling valued can boost loyalty. Lack of communication or irrelevant messaging can lead to disengagement.
  7. Onboarding Process: For new customers, the initial experience is crucial. A smooth, informative, and supportive onboarding process sets the stage for long-term satisfaction. A difficult or confusing onboarding can create detractors from the outset.
  8. Competitive Landscape: Customers often compare their experience with your company to alternatives. If competitors offer a significantly better product, price, or service, it can negatively impact your NPS, even if your offering is adequate. Staying competitive is essential.

Frequently Asked Questions (FAQ)

What is the ideal NPS score?
There isn't a single "ideal" NPS score, as it varies significantly by industry. However, generally:
  • Above 50: Often considered "Excellent."
  • 30-50: Considered "Good."
  • 10-30: Considered "Fair."
  • Below 10: Often considered "Needs Improvement."
  • Below 0: Indicates more detractors than promoters and requires urgent attention.
It's best to benchmark your score against competitors in your specific industry.
Can NPS be negative?
Yes, the NPS score can be negative. This occurs when the number of Detractors is greater than the number of Promoters. A negative NPS indicates that your company has more unhappy customers than happy ones, highlighting a significant need for improvement in customer experience.
What is the difference between NPS and CSAT?
NPS (Net Promoter Score) measures overall customer loyalty and likelihood to recommend, typically using a 0-10 scale. CSAT (Customer Satisfaction) measures satisfaction with a specific interaction or product feature, usually on a scale like 1-5 or using a satisfaction/dissatisfaction scale. NPS provides a broader view of loyalty, while CSAT offers granular feedback on specific touchpoints. You can use our NPS survey calculator and explore other tools to track both.
How often should I measure NPS?
The frequency depends on your business model and customer lifecycle. For businesses with frequent customer interactions (e.g., SaaS, retail), quarterly or even monthly NPS surveys can be beneficial. For businesses with longer sales cycles or less frequent interactions (e.g., large B2B services), semi-annually or annually might be more appropriate. Consistency is key for tracking trends.
What if I have very few responses?
A low number of responses can make your NPS score less statistically reliable. While the NPS survey calculator will still compute a score, it might not accurately represent your entire customer base. Consider strategies to increase survey participation, such as offering incentives or improving survey design. Ensure your sample size is representative of your customer segments.
Should I include Passives in the NPS calculation?
No, the standard NPS formula only subtracts the percentage of Detractors from the percentage of Promoters. Passives are not directly included in the score calculation. However, understanding the percentage of Passives is crucial for strategy, as they represent a significant group that could potentially be converted into Promoters.
How can I improve my NPS score?
Improving NPS involves a multi-faceted approach:
  • Actively listen to feedback from both Promoters and Detractors.
  • Address the specific pain points mentioned by Detractors.
  • Enhance customer service responsiveness and quality.
  • Improve product features and user experience based on feedback.
  • Create loyalty programs or exclusive benefits for Promoters.
  • Engage Passives by understanding their hesitations and offering solutions.
Regularly using the NPS survey calculator will help you track the impact of these initiatives.
What are the limitations of NPS?
NPS has limitations:
  • It's a single metric and doesn't explain the 'why' on its own. Qualitative feedback is essential.
  • Scores can be influenced by cultural differences and individual response biases.
  • It may not capture satisfaction with specific product features or service interactions as well as CSAT.
  • Benchmarking can be difficult if methodologies differ across companies.
Despite these, it remains a valuable tool for measuring overall customer loyalty when used correctly.

NPS Response Distribution

Promoters
Passives
Detractors
Distribution of customer responses across Promoter, Passive, and Detractor categories.

© 2023 Your Company Name. All rights reserved.

var chartInstance = null; // Global variable to hold chart instance function validateInput(id, errorId, minValue = 0, maxValue = Infinity) { var input = document.getElementById(id); var errorElement = document.getElementById(errorId); var value = parseFloat(input.value); errorElement.textContent = "; // Clear previous error if (isNaN(value)) { errorElement.textContent = 'Please enter a valid number.'; return false; } if (value maxValue) { errorElement.textContent = 'Value exceeds maximum limit.'; return false; } return true; } function calculateNPS() { var totalResponses = document.getElementById('totalResponses'); var promoters = document.getElementById('promoters'); var passives = document.getElementById('passives'); var detractors = document.getElementById('detractors'); var totalResponsesError = document.getElementById('totalResponsesError'); var promotersError = document.getElementById('promotersError'); var passivesError = document.getElementById('passivesError'); var detractorsError = document.getElementById('detractorsError'); var isValid = true; isValid = validateInput('totalResponses', 'totalResponsesError') && isValid; isValid = validateInput('promoters', 'promotersError') && isValid; isValid = validateInput('passives', 'passivesError') && isValid; isValid = validateInput('detractors', 'detractorsError') && isValid; if (!isValid) { return; } var numTotalResponses = parseFloat(totalResponses.value); var numPromoters = parseFloat(promoters.value); var numPassives = parseFloat(passives.value); var numDetractors = parseFloat(detractors.value); // Recalculate total based on inputs if they sum up differently var calculatedTotal = numPromoters + numPassives + numDetractors; if (calculatedTotal !== numTotalResponses) { // If the sum of P+Pa+D doesn't match Total Responses, use the sum as the effective total for percentage calculation // Or, alternatively, warn the user. For simplicity, we'll use the sum. // A more robust approach might involve adjusting one of the inputs or showing a warning. // For this calculator, we'll prioritize the sum of P+Pa+D for percentage calculations if it differs from Total Responses input. // However, we still display the user-inputted Total Responses for clarity. // Let's stick to the user-inputted total for percentage calculation as per standard NPS practice. // If the user inputs mismatch, it's their responsibility. // We will validate that P+Pa+D numTotalResponses) { detractorsError.textContent = 'Sum of Promoters, Passives, and Detractors cannot exceed Total Responses.'; promotersError.textContent = "; passivesError.textContent = "; return; // Stop calculation if sum exceeds total } // If sum is less than total, the remaining are implicitly 'unanswered' or 'invalid' for NPS calculation purposes. // We use the user-inputted numTotalResponses for the denominator. } var promoterPercentage = (numPromoters / numTotalResponses) * 100; var detractorPercentage = (numDetractors / numTotalResponses) * 100; var passivePercentage = (numPassives / numTotalResponses) * 100; var npsScore = promoterPercentage – detractorPercentage; // Round percentages and NPS score promoterPercentage = promoterPercentage.toFixed(2); detractorPercentage = detractorPercentage.toFixed(2); passivePercentage = passivePercentage.toFixed(2); npsScore = npsScore.toFixed(2); document.getElementById('npsScoreResult').textContent = npsScore; document.getElementById('promoterPercentage').textContent = 'Promoters: ' + promoterPercentage + '%'; document.getElementById('passivePercentage').textContent = 'Passives: ' + passivePercentage + '%'; document.getElementById('detractorPercentage').textContent = 'Detractors: ' + detractorPercentage + '%'; document.getElementById('totalResponsesUsed').textContent = 'Total Responses Used: ' + numTotalResponses; var npsCategoryElement = document.getElementById('npsCategory'); var npsCategoryText = "; var npsCategoryColor = '#6c757d'; // Default grey if (npsScore >= 70) { npsCategoryText = 'World Class'; npsCategoryColor = 'var(–success-color)'; } else if (npsScore >= 50) { npsCategoryText = 'Excellent'; npsCategoryColor = 'var(–success-color)'; } else if (npsScore >= 30) { npsCategoryText = 'Good'; npsCategoryColor = 'var(–primary-color)'; } else if (npsScore >= 10) { npsCategoryText = 'Fair'; npsCategoryColor = '#fd7e14'; // Orange } else if (npsScore >= 0) { npsCategoryText = 'Needs Improvement'; npsCategoryColor = '#ffc107'; // Yellow } else { npsCategoryText = 'Poor – Requires Urgent Action'; npsCategoryColor = 'var(–error-color)'; } npsCategoryElement.textContent = npsCategoryText; npsCategoryElement.style.backgroundColor = npsCategoryColor; updateChart(numPromoters, numPassives, numDetractors, numTotalResponses); } function resetCalculator() { document.getElementById('totalResponses').value = '1000'; document.getElementById('promoters').value = '500'; document.getElementById('passives').value = '300'; document.getElementById('detractors').value = '200'; document.getElementById('totalResponsesError').textContent = "; document.getElementById('promotersError').textContent = "; document.getElementById('passivesError').textContent = "; document.getElementById('detractorsError').textContent = "; document.getElementById('npsScoreResult').textContent = '–'; document.getElementById('promoterPercentage').textContent = 'Promoters: –%'; document.getElementById('passivePercentage').textContent = 'Passives: –%'; document.getElementById('detractorPercentage').textContent = 'Detractors: –%'; document.getElementById('totalResponsesUsed').textContent = 'Total Responses Used: –'; document.getElementById('npsCategory').textContent = '–'; document.getElementById('npsCategory').style.backgroundColor = 'var(–primary-color)'; // Reset to default // Clear chart if it exists if (chartInstance) { chartInstance.destroy(); chartInstance = null; } // Optionally redraw with default values or clear canvas var ctx = document.getElementById('npsChart').getContext('2d'); ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); } function copyResults() { var npsScore = document.getElementById('npsScoreResult').textContent; var promoterPerc = document.getElementById('promoterPercentage').textContent; var passivePerc = document.getElementById('passivePercentage').textContent; var detractorPerc = document.getElementById('detractorPercentage').textContent; var totalResponses = document.getElementById('totalResponsesUsed').textContent; var npsCategory = document.getElementById('npsCategory').textContent; var assumptions = "NPS Calculation Assumptions:\n" + "Total Responses: " + totalResponses.split(': ')[1] + "\n" + "Promoters (%): " + promoterPerc.split(': ')[1] + "\n" + "Passives (%): " + passivePerc.split(': ')[1] + "\n" + "Detractors (%): " + detractorPerc.split(': ')[1]; var resultsText = "NPS Results:\n" + "Score: " + npsScore + "\n" + "Category: " + npsCategory + "\n\n" + assumptions; // Use Clipboard API if available, fallback to prompt if (navigator.clipboard && window.isSecureContext) { navigator.clipboard.writeText(resultsText).then(function() { var feedback = document.getElementById('copyFeedback'); feedback.style.display = 'block'; setTimeout(function() { feedback.style.display = 'none'; }, 3000); }).catch(function(err) { console.error('Failed to copy text: ', err); // Fallback for environments where clipboard API fails or is not permitted prompt("Copy the following text:", resultsText); }); } else { // Fallback for older browsers or insecure contexts try { var textArea = document.createElement("textarea"); textArea.value = resultsText; textArea.style.position = "fixed"; // Avoid scrolling to bottom textArea.style.left = "-9999px"; textArea.style.top = "-9999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); document.execCommand('copy'); document.body.removeChild(textArea); var feedback = document.getElementById('copyFeedback'); feedback.style.display = 'block'; setTimeout(function() { feedback.style.display = 'none'; }, 3000); } catch (err) { console.error('Failed to copy text using fallback: ', err); prompt("Copy the following text:", resultsText); } } } function updateChart(promoters, passives, detractors, total) { var ctx = document.getElementById('npsChart').getContext('2d'); // Destroy previous chart instance if it exists if (chartInstance) { chartInstance.destroy(); } // Calculate percentages for chart var promoterPerc = total > 0 ? (promoters / total) * 100 : 0; var passivePerc = total > 0 ? (passives / total) * 100 : 0; var detractorPerc = total > 0 ? (detractors / total) * 100 : 0; // Ensure percentages sum up reasonably close to 100% if total is used correctly // If calculatedTotal was used, this might be slightly different. // For simplicity, we'll use the calculated percentages based on the provided total. chartInstance = new Chart(ctx, { type: 'bar', data: { labels: ['Promoters', 'Passives', 'Detractors'], datasets: [{ label: 'Response Percentage', data: [promoterPerc, passivePerc, detractorPerc], backgroundColor: [ 'rgba(40, 167, 69, 0.7)', // Green for Promoters 'rgba(255, 193, 7, 0.7)', // Yellow for Passives 'rgba(220, 53, 69, 0.7)' // Red for Detractors ], borderColor: [ 'rgba(40, 167, 69, 1)', 'rgba(255, 193, 7, 1)', 'rgba(220, 53, 69, 1)' ], borderWidth: 1 }] }, options: { responsive: true, maintainAspectRatio: false, scales: { y: { beginAtZero: true, max: 100, ticks: { callback: function(value) { return value + '%'; } } } }, plugins: { legend: { display: false // Legend is handled by custom div }, tooltip: { callbacks: { label: function(context) { var label = context.dataset.label || "; if (label) { label += ': '; } if (context.parsed.y !== null) { label += context.parsed.y.toFixed(2) + '%'; } return label; } } } } } }); } // Initial calculation on page load document.addEventListener('DOMContentLoaded', function() { calculateNPS(); // Perform initial calculation with default values // Add event listeners for input changes to update chart dynamically var inputs = document.querySelectorAll('.loan-calc-container input[type="number"]'); inputs.forEach(function(input) { input.addEventListener('input', function() { // Re-validate and recalculate on input change var isValid = true; isValid = validateInput('totalResponses', 'totalResponsesError') && isValid; isValid = validateInput('promoters', 'promotersError') && isValid; isValid = validateInput('passives', 'passivesError') && isValid; isValid = validateInput('detractors', 'detractorsError') && isValid; if (isValid) { calculateNPS(); // Recalculate and update chart } }); }); // FAQ toggle functionality var faqQuestions = document.querySelectorAll('.faq-question'); faqQuestions.forEach(function(question) { question.addEventListener('click', function() { var answer = this.nextElementSibling; this.classList.toggle('active'); if (answer.style.display === 'block') { answer.style.display = 'none'; } else { answer.style.display = 'block'; } }); }); }); // Chart.js library is required for the canvas chart. // In a real WordPress environment, you would enqueue this script properly. // For this standalone HTML, we assume Chart.js is available globally. // If not, you'd need to include the Chart.js CDN link in the . // Example: // For this output, we assume it's present.

Leave a Comment