35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
const serverSelect = document.querySelector("select[name=serverinfo_uid]");
|
|
const rackSelect = document.querySelector("select[name=rack]");
|
|
const lineSelect = document.querySelector("select[name=line]");
|
|
const titleInput = document.querySelector("input[name=title]");
|
|
const amountInput = document.querySelector("input[name=amount]");
|
|
|
|
function getTotalPrice() {
|
|
const serverPrice = serverSelect?.options[serverSelect.selectedIndex]?.getAttribute("data-price") || 0;
|
|
const rackPrice = rackSelect?.options[rackSelect.selectedIndex]?.value || 0;
|
|
const linePrice = lineSelect?.options[lineSelect.selectedIndex]?.value || 0;
|
|
return Number(serverPrice) + Number(rackPrice) + Number(linePrice);
|
|
}
|
|
|
|
// 공통 업데이트 함수
|
|
function updateAmount() {
|
|
if (amountInput) {
|
|
amountInput.value = getTotalPrice();
|
|
}
|
|
}
|
|
|
|
// 이벤트 리스너 등록
|
|
if (rackSelect) rackSelect.addEventListener("change", updateAmount);
|
|
if (lineSelect) lineSelect.addEventListener("change", updateAmount);
|
|
// ✅ select2는 전용 이벤트 사용
|
|
if (serverSelect) {
|
|
$(serverSelect).on("select2:select", function () {
|
|
updateAmount();
|
|
if (titleInput) {
|
|
titleInput.value = serverSelect?.options[serverSelect.selectedIndex]?.text || "";
|
|
}
|
|
});
|
|
}
|
|
|
|
//페이지 로드 시 초기 실행
|
|
document.addEventListener("DOMContentLoaded", updateAmount); |