Home / Widgets / Child Support Calculator
Duplicate Snippet

Embed Snippet on Your Site

Child Support Calculator

Jeremy Setters
<10
Code Preview
php
<?php
function child_support_calculator_shortcode() {
    // Enqueue the JavaScript
    wp_enqueue_script('child-support-calculator', get_template_directory_uri() . '/path-to-your-js-folder/child-support-calculator.js', array('jquery'), '1.0.0', true);
    ob_start();
    include get_template_directory() . '/path-to-your-html-folder/child-support-form.html';
    return ob_get_clean();
}
add_shortcode('child_support_calculator', 'child_support_calculator_shortcode');
Javascript
document.addEventListener("DOMContentLoaded", function() {
    document.getElementById("childSupportForm").addEventListener("submit", function(event) {
        event.preventDefault();
        const grossIncome = parseFloat(document.getElementById("grossIncome").value);
        let numChildren = parseInt(document.getElementById("numChildren").value);
        let supportAmount = 0;
        // Define your percentages here
        const basePercentages = [
            [0.16, 0.08, 0.04], 
            [0.22, 0.11, 0.06], 
            [0.26, 0.13, 0.06],
            [0.28, 0.14, 0.07]
        ];
        
        // If number of children is above 4, calculate based on increments
        if (numChildren > 4) {
            supportAmount += calculateAmount(grossIncome, basePercentages[3]);
            numChildren -= 4;
            while(numChildren > 0) {
                supportAmount += calculateAmount(grossIncome, [0.02, 0.01, 0.005]);
                numChildren--;
            }
        } else {
            supportAmount = calculateAmount(grossIncome, basePercentages[numChildren - 1]);
        }
        document.getElementById("result").innerText = "Child Support Amount: $" + supportAmount.toFixed(2);
    });
    function calculateAmount(income, percentages) {
        let amount = 0;
        amount += percentages[0] * Math.min(income, 6000);
        if (income > 6000) amount += percentages[1] * (Math.min(income, 10000) - 6000);
        if (income > 10000) amount += percentages[2] * (income - 10000);
        return amount;
    }
});

Comments

Add a Comment