Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [help]is there any way to make this jquery code shorter and efficient Re: [help]is there any way to make this jquery code shorter and efficient

#111323
vhinmanansala
Participant

Hi nikuls, thanks for your effort in helping me. the problem with the code above is that when i try to increase the loan cost, the monthly payment don’t appear as it don’t get the index of the 12 and 24 month duration. So i made a few tweaks with the code you gave me and here is my code

$(document).ready(function() {
var loan_cost = $('#slider-1').val();
var index = null;
var loan_cost_arr = ["5000", "10000", "15000", "20000", "25000"];
var months12 = ["438.36", "872.46", "1'308.69", "1'744.9", "2'181.15"];
var months24 = ["229.52", "454.81", "682.22", "909.63", "1'137.04"];
var months36 = ["160.11", "315.94", "473.9", "631.87", "789.84"];
var months48 = ["125.56", "246.75", "370.12", "493.5", "616.87"];
var months60 = ["104.95", "205.44", "308.16", "410.87", "513.59"];

$( "#slider-1" ).bind( "change", function(event, ui) {
loan_cost = $(this).slider().val();
index = jQuery.inArray(loan_cost, loan_cost_arr);

if ($('#12-month').is(':checked')){
$('#monthly-payment').val(months12[index]);
}else if ($('#24-month').is(':checked')){
$('#monthly-payment').val(months24[index]);
}else if ($('#36-month').is(':checked')){
$('#monthly-payment').val(months36[index]);
}else if ($('#48-month').is(':checked')){
$('#monthly-payment').val(months48[index]);
}else if ($('#60-month').is(':checked')){
$('#monthly-payment').val(months60[index]);
}
});
});

Thanks for this great help, really appreciate it :) God Bless