Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScriptCost calculator

    Making a website for nonprofit and I don't know why my cost calculator isn't working. Using Drupal 7.

    <script type="text/javascript" src="http://www.ccdlex.org/sites/all/themes/corporateclean/js/feecalculator.js"></script>

    <p>Counselors are sensitive to the client's individual financial circumstance. Fees for services are based on a sliding scale that considers household income as well as family size. Fees are quoted when a potential client calls for information. In addition, many insurances carriers are accepted. </p>
    <p>Counselors are also available to provide group therapy or educational workshops on a contract basis.</p>
    <p>For further information or to make an appointment, please contact the counseling department at (859) 253-1993 in Lexington and (606) 874-9170 in Prestonsburg and ask for a counselor.</p>
    <div>Evening appointments are available.</div>
    <div>&nbsp;</div>
    <div><em>This program receives financial support from United Way of the Bluegrass and United Way of Eastern Kentucky.</em></div><em></em>
    <div><em></em></div>
    <h2>Catholic Charities Clinical Counseling Fees</h2>Fees will be subsidized by the Diocese of Lexington, United Way and Catholic Charities' benefactors for uninsured or underinsured clientswho can not afford the fees.<br />
    <br />
    Fill in the fields below with household income and the number of people in the household to calculate the fee/co-pay recommended by our board.<br />
    <br />
    <strong>HOUSEHOLD INCOME</strong>
    <input id="income" class="form" name="" type="text" />
    <strong>FAMILY SIZE</strong>
    <input id="family" class="form" name="" type="text" />
    <input id="calcbutton" class="form" value="Calculate" type="button" /><br />
    <script type="text/javascript">
    //<![CDATA[
    var feecalc = null;$(document).ready(function(e) { feecalc = new feecalculator(); feecalc.init();});
    //]]>
    </script>


    <table id="copaytable" style="display:none" cellpadding="0" cellspacing="0">
    <tbody>
    <tr>
    <td style="padding:0px; border-spacing:0px"><strong>FEE/CO-PAY FOR 45-50 MIN</strong></td>
    <td><span id="fee"></span></td>
    </tr>
    <tr>
    <td style="padding:0px; border-spacing:0px"><strong>FEE/CO-PAY FOR 75-80 MIN</strong></td>
    <td><span id="fee2"></span></td>
    </tr>
    <tr>
    <td style="padding:0px; border-spacing:0px"><strong>FEE/CO-PAY FOR INTAKE OR 90-100 MIN</strong></td>
    <td><span id="fee3"></span></td>
    </tr>
    </tbody>
    </table><br />

    Length of session impacts the fee charged.<br />
    No one will be charged more than $100 for a 45-50 minute session.<br />
    However, ALL intake sessions cost double the recommended fee because they generally take more than 90 minutes.<br />
    Sessions held on the phone due to weather or travel difficulties will be charged at the same rate.<br />
    No fee is charged for inquiries about services or phone calls to change or cancel appointments.<br />


    <script type="text/javascript">
    //<![CDATA[
    var feecalc = null;$(document).ready(function(e) { feecalc = new feecalculator(); feecalc.init();});
    //]]>
    </script>

    Attatched script



    function feecalculator() {

    this.family = 0;
    this.income = 0;

    this.familylimits = Array();
    this.familylimits[1] = 10900;
    this.familylimits[2] = 14700;
    this.familylimits[3] = 18400;
    this.familylimits[4] = 22200;
    this.familylimits[5] = 25900;
    this.familylimits[6] = 29600;
    this.familylimits[7] = 33400;
    this.familylimits[8] = 37100;
    this.familylimits[9] = 40800;
    this.familylimits[10] = 44600;
    this.familylimits[11] = 48300;
    this.familylimits[12] = 52100;

    this.init = function()
    {

    $('#family, #income').keypress(function(event) {
    return feecalc.inputLimiter(event,'Numbers');
    });

    $('#calcbutton').bind('click', this, function(e) {
    e.data.getFee();
    });

    $('#family').bind('change blur', this, function(e) {

    if ($(this).val()>12)
    {
    $(this).val(12)
    }

    e.data.family = $(this).val();
    //e.data.getFee();

    });

    $('#income').bind('change blur', this, function(e) {

    value = $(this).val();
    if ( value % 100 != 0 )
    {
    count = 0;
    while( value % 100 != 0 )
    {
    value++;
    count++;
    }

    if (count<=50)
    {
    $(this).val(value);
    }
    else
    {
    value = value-count;
    while( value % 100 != 0 )
    {
    value--;
    }
    $(this).val(value);
    }
    }


    e.data.income = $(this).val();
    //e.data.getFee();

    });

    }


    this.getFee = function()
    {
    var copayfee;
    var copayfee2;
    var copayfee3;
    if ( this.income>0 && this.family>0 )
    {
    if (this.income>=this.familylimits[this.family])
    {
    copayfee = Math.round( (this.income * 0.001)/this.family );
    copayfee2 = Math.round(copayfee * 1.5);
    copayfee3 = Math.round(copayfee * 2);

    if (fee>100) fee=100;

    $('#fee').text('$'+copayfee);
    $('#fee2').text('$'+copayfee2);
    $('#fee3').text('$'+copayfee3);
    $('#copaytable').show();
    }
    else
    {
    copayfee = '0';
    copayfee2 = '0';
    copayfee3 = '0';
    }

    $('#fee').text('$'+copayfee);
    $('#fee2').text('$'+copayfee2);
    $('#fee3').text('$'+copayfee3);
    $('#copaytable').show();
    }
    else if ( this.income==0 && this.family==0 )
    {
    alert('Please enter your household income and your family size.');
    }
    else if ( this.income==0)
    {
    alert('Please enter your household income.');
    }
    else if ( this.family==0 )
    {
    alert('Please enter your family size.');
    }

    }


    this.inputLimiter = function(e,allow)
    {
    var AllowableCharacters = '';

    if (allow == 'Letters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';}
    if (allow == 'Numbers'){AllowableCharacters='1234567890';}
    if (allow == 'NameCharacters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.\'';}
    if (allow == 'NameCharactersAndNumbers'){AllowableCharacters='1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-\'';}

    var k = document.all?parseInt(e.keyCode): parseInt(e.which);
    if (k!=13 && k!=8 && k!=0){
    if ((e.ctrlKey==false) && (e.altKey==false)) {
    return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1);
    } else {
    return true;
    }
    } else {
    return true;
    }
    }

    }

  • #2
    Regular Coder
    Join Date
    Jul 2011
    Posts
    101
    Thanks
    7
    Thanked 6 Times in 6 Posts
    Unfortunately, that's way beyond my skill level. But please contain any code in the [Code] tags in the future.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,037
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Please have a look at the advice given in MUST READ- How to post a JavaScript question!
    and the Forum Posting Guidelines, escpecially about the use of [code] tags and only posting the part of the script you are having trouble with. You cannot expect people to wade through all that code when you give so few clues as to what is not working as you expect.

    Have you tried using your error console? What error messages do you receive?

    It's unthinkable that racing might not go ahead today because of the weather. Although obviously it might not. - bv Racing commentator, BBC Radio 3.
    Last edited by Philip M; 03-25-2013 at 08:20 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    That is some truly ugly coding.

    And it's using jQuery for no reasons that I can see.

    It would be easier (for me!) to just toss it out and rewrite it from scratch.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •