Created
March 18, 2013 18:40
-
-
Save developdaly/5189640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
getRate( 'Dealer: New', 72, 72, '.rate-new-72-72' ); | |
}); | |
/** | |
* Retrieves the interest rate for given minimum and maximum month terms. | |
* | |
* @arg type string Required. The description of the product. | |
* @arg min int Required. Minimum months for set of terms. | |
* @arg max int Required. Maximum months for set of terms. | |
* @arg selector string Required. The HTML selector in the format of #example or .example | |
* that the rate will replace. | |
* @return integer. Interest rate in "X.XX" format | |
*/ | |
function getRate( type, min, max, selector ) { | |
"use strict"; | |
$.ajax({ | |
type: "GET", | |
url: "/rates/rates.aspx", | |
dataType: "xml", | |
success: function( xml ) { | |
var apr; | |
// Loop through each product | |
$(xml).find( 'product' ).each(function(){ | |
// If the product's attribute equals the given type, proceed | |
if($(this).attr('product_description_html') == type ) { | |
// Loop through each term set | |
$(this).find( 'interest_adjustment' ).each(function() { | |
// Return the interest rate of the given terms | |
if( ( min == $(this).attr( 'min_loan_term' ) ) && ( max == $(this).attr( 'max_loan_term' ) ) ) { | |
var apr = $(this).attr( 'interest_adjustment' ); | |
$(selector).text( apr ); | |
} | |
}); | |
} | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment