JavaScript
54
Вклад в тег
var err = 'выберите разные города';
prices = {
khabarovsk: {
khabarovsk: err,
moscow: 1200,
spb: 1000,
rdn: 750,
smr: 888
},
moscow: {
khabarovsk: 1200,
moscow: err,
spb: 500,
rdn: 650,
smr: 777
},
spb: {
khabarowsk: 1000,
moscow: 500,
spb: err,
rdn: 550,
smr: 555,
},
rdn: {
khabarowsk: 750,
moscow: 650,
spb: 550,
rdn: err,
smr: 444
},
smr: {
khabarowsk: 750,
moscow: 650,
spb: 550,
rdn: 888,
smr: err
}
};
$( "select.city_choice" ).change(function() {
$('.final_price').html(prices[$('#city_from').val()][$('#city_to').val()]);
});
var err = 'выберите разные города';
altprices = [
['moscow','khabarovsk',1200],
['moscow','spb',500],
['moscow','rdn',650],
['moscow','smr',777],
['khabarovsk','spb',1000],
['khabarovsk','rdn',750],
['khabarovsk','smr',888],
['spb','rdn',550],
['spb','smr',555],
['rdn','smr',444]
];
$( "select.city_choice2" ).change(function() {
for(var i = 0; i < altprices.length;i++){
if ($('#city_from2').val() == $('#city_to2').val()) {
$('.final_price2').html(err);
return;
}
if($.inArray($('#city_from2').val(), altprices[i]) != -1 && $.inArray($('#city_to2').val(), altprices[i]) != -1){
$('.final_price2').html(altprices[i][2]);
}
}
});