-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (38 loc) · 1.2 KB
/
Copy pathscript.js
File metadata and controls
45 lines (38 loc) · 1.2 KB
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
const form = document.getElementById("lead-form");
form.addEventListener("submit", async function (e) {
e.preventDefault();
const phoneInput = document.getElementById("phone").value.trim();
const nameInput = document.getElementById("name").value.trim();
if (phoneInput.length < 13) {
alert(
"Iltimos, telefon raqamingizni to'liq kiriting! (Masalan: +998991234567)",
);
return;
}
const formData = new FormData(form);
try {
const response = await fetch(form.action, {
method: form.method,
body: formData,
headers: {
Accept: "application/json",
},
});
if (response.ok) {
alert(
`Rahmat, ${nameInput}! Arizangiz muvaffaqiyatli qabul qilindi. Tez orada American Academy administratorlari siz bilan bog'lanishadi.`,
);
form.reset();
document.getElementById("phone").value = "+998";
} else {
alert("Xatolik yuz berdi. Iltimos, formani qaytadan to'ldirib ko'ring.");
}
} catch (error) {
alert("Internet aloqasini tekshiring va qaytadan urining.");
}
});
document.getElementById("phone").addEventListener("input", function (e) {
if (!this.value.startsWith("+998")) {
this.value = "+998";
}
});