I made a JavaScript calculator to calculate the price for counseling. I had it working in the old webpage and I'm converting to Drupal 7. Even though it worked before, I'm recieving an error now.
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;
}
}
}
//<![CDATA[
var feecalc = null;$(document).ready(function(e) { feecalc = new feecalculator(); feecalc.init();});
//]]>