Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 8bfa5ed1 authored by 65160270's avatar 65160270
Browse files

update-address

parent 106a2891
Branches
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<a href="/" class="continue-shopping" >Continue Shopping</a> <a href="/" class="continue-shopping" >Continue Shopping</a>
</div> </div>
<div class="info-section"> <div class="info-section">
<h3>edit Address</h3> <h3>Shipping Address</h3>
<p> <p>
<span id="shipping-address"><%= order.shipping_address %></span> <span id="shipping-address"><%= order.shipping_address %></span>
<input type="text" id="new-address" value="<%= order.shipping_address %>" style="display:none;"> <input type="text" id="new-address" value="<%= order.shipping_address %>" style="display:none;">
...@@ -14,4 +14,37 @@ ...@@ -14,4 +14,37 @@
<button id="edit-btn">แก้ไขที่อยู่</button> <button id="edit-btn">แก้ไขที่อยู่</button>
<button id="save-btn" style="display:none;">บันทึก</button> <button id="save-btn" style="display:none;">บันทึก</button>
</div> </div>
<script>
document.getElementById("edit-btn").addEventListener("click", function() {
document.getElementById("new-address").style.display = "inline";
document.getElementById("save-btn").style.display = "inline";
document.getElementById("edit-btn").style.display = "none"; // ซ่อนปุ่มแก้ไข
});
document.getElementById("save-btn").addEventListener("click", async function() {
const newAddress = document.getElementById("new-address").value.trim();
if (!newAddress) {
alert("กรุณากรอกที่อยู่ใหม่");
return;
}
const orderId = "<%= order.id %>";
const response = await fetch(`/order/update/${orderId}`, { // แก้ให้ตรง API
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ shipping_address: newAddress })
});
if (response.ok) {
document.getElementById("shipping-address").innerText = newAddress;
document.getElementById("new-address").style.display = "none";
document.getElementById("save-btn").style.display = "none";
document.getElementById("edit-btn").style.display = "inline";
alert("อัปเดตที่อยู่สำเร็จ!");
} else {
alert("เกิดข้อผิดพลาด!");
}
});
</script>
<%- include('partials/footer') %> <%- include('partials/footer') %>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment