-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
127 lines (107 loc) · 3.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const scrollButton = document.getElementById("scrollBtn");
const targetSection = document.getElementById("targetSec");
scrollButton.addEventListener("click", () => {
const targetPosition = targetSection.offsetTop;
window.scrollTo({
top: targetPosition,
behavior: "smooth"
});
});
const scrollButtonn = document.getElementById("scrollBtn1");
const targetSectionn = document.getElementById("targetSec1");
scrollButtonn.addEventListener("click", () => {
const targetPosition = targetSection.offsetTop;
window.scrollTo({
top: targetPosition,
behavior: "smooth"
});
});
function showButton() {
let checkbox = document.getElementById("myCheckbox");
let button = document.getElementById("myButton");
if (checkbox.checked) {
button.style.display = "block";
} else {
button.style.display = "none";
}
}
let service=""
function showDescription(product) {
let cardss = document.getElementsByClassName("cards");
for (let i = 0; i < cardss.length; i++) {
let card = cardss[i];
let title = card.getElementsByTagName("h2")[0].textContent;
let description = card.getElementsByClassName("description")[0].textContent;
if (title === product) {
console.log("inline");
document.getElementById("selectedServiceId").textContent = description;
document.getElementById("selectedServiceId").style.display = "block";
service = product
}
}
}
const submitButton=document.getElementById("submit_button")
submitButton.addEventListener("click", async() => {
const firstName = document.getElementById('tbFirstName').value
const LastName = document.getElementById('tbLastName').value
const telRange = document.getElementById('tbTelRange').value
const AreaCode = document.getElementById('tbAreaCode').value
const mobile = document.getElementById('tbMobile').value
const url = "https://store.pishgaman.net/Order/SubmitOrder";
const data = {
selectedServiceId: service,
tbFirstName : firstName,
tbLastName : LastName,
tbTelRange : telRange,
tbAreaCode : AreaCode,
tbMobile : mobile,
};
await fetch(url, {
method: 'POST',
// mode:"cors",
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
return response.json();
})
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
});
function validateFormAndItems() {
let tbFirstName = document.getElementById('tbFirstName').value.trim();
let tbLastName = document.getElementById('tbLastName').value.trim();
let tbAreaCode = document.getElementById('tbAreaCode').value.trim();
let tbTelRange = document.getElementById('tbTelRange').value.trim();
let tbMobile = document.getElementById('tbMobile').value.trim();
if (tbFirstName === '' || tbLastName === '' || tbAreaCode === '' || tbTelRange === '' || tbMobile === '') {
alert('لطفا تمام فیلدهای فرم را پر کنید');
return false;
}
let selectedServiceDiv = document.getElementById('selectedServiceId');
if (selectedServiceDiv.style.display === 'none') {
let selectedItems = document.querySelectorAll('.selected-item');
if (selectedItems.length === 0) {
alert('لطفا سرویس مورد نظر خود را انتخاب نمایید.');
return false;
}
} else {
const success =
document.getElementById("submit_button").addEventListener("click", () => {
let alertElement = document.getElementById("alertMessage");
alertElement.innerHTML = "همکاران ما به زودی با شما تماس میگیرند";
alertElement.style.display = "block";
});
console.log(success)
}
return true;
}