Вообщем у меня есть 2 select`а и у каждого из них есть on change, так вот мне надо когда я передал данные из одного select в другой, этот on change запустить это возможно? Вот мой код который передаёт данные:
$(".select_razmer").on('change', function () {
var money = this.options[this.selectedIndex].attributes['data-money'].value;
var default_price = this.options[this.selectedIndex].attributes['data-price'].value;
var product_id = this.options[this.selectedIndex].attributes['data-id_product'].value;
$('#product_popup_' + product_id + ' .popup-body .popup-product__content .popup-product__content_text .cart-list__item-razmer .select_razmer_main').val($(this).val());
var new_money = 0;
console.log(money);
console.log(default_price);
if (money > 0) {
new_money = parseInt(default_price) + parseInt(money);
console.log('Плюс ' + new_money);
$(this).parent().next().children('.row').children('.price_product_one').html(number_format(new_money, 2, ',', ' ') + ' руб.');
} else {
new_money = parseInt(default_price) + parseInt(money);
console.log('Минус ' + new_money);
$(this).parent().next().children('.row').children('.price_product_one').html(number_format(new_money, 2, ',', ' ') + ' руб.');
}
});
$(".select_razmer_main").on('change', function () {
var money = this.options[this.selectedIndex].attributes['data-money'].value;
var default_price = this.options[this.selectedIndex].attributes['data-price'].value;
var product_id = this.options[this.selectedIndex].attributes['data-id_product'].value;
var elements = document.getElementsByTagName('tr');
for (var i = 0; i < elements.length; i++) {
if (elements[i].getAttribute('data-key') === product_id) {
var tr_elem = elements[i];
}
}
$(tr_elem).children([3]).children(".select_razmer").val($(this).val());
var new_money = 0;
console.log(money);
console.log(default_price);
if (money > 0) {
new_money = parseInt(default_price) + parseInt(money);
console.log('Плюс ' + new_money);
$(this).parent().next().children('.row').children('.price_product_one').html(number_format(new_money, 2, ',', ' ') + ' руб.');
} else {
new_money = parseInt(default_price) + parseInt(money);
console.log('Минус ' + new_money);
$(this).parent().next().children('.row').children('.price_product_one').html(number_format(new_money, 2, ',', ' ') + ' руб.');
}
});
Ну думаю суть понятна.
Вы не боитесь зациклить два Ваши обработчика? Может быть не вызывать change, если значение не изменяется?
var otherSelect = $('#product_popup_' + product_id + ' .popup-body .popup-product__content .popup-product__content_text .cart-list__item-razmer .select_razmer_main');
if (otherSelect.val() != $(this).val());
otherSelect.val($(this).val()).change();
var otherSelect = $(tr_elem).children([3]).children(".select_razmer");
if (otherSelect.val() != $(this).val());
otherSelect.val($(this).val()).change();
Кхм, кхм. Не
var elements = document.getElementsByTagName('tr');
for (var i = 0; i < elements.length; i++) {
if (elements[i].getAttribute('data-key') === product_id) {
var tr_elem = elements[i];
}
}
a
var tr_elem = $("tr[data-key='" + product_id + "'");
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости