-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
70 lines (59 loc) · 2.21 KB
/
script.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
function changeVersion() {
var selectElement = document.getElementById("versions");
var selectedVersion = selectElement.value;
// Redirect ke halaman yang dipilih
if (selectedVersion) {
window.location.href = selectedVersion;
}
}
document
.getElementById("contactForm")
.addEventListener("submit", function (event) {
event.preventDefault(); // utk mencegah formulir terkirim
// ambil nilai input melalui id
const nama = document.getElementById("nama").value;
const email = document.getElementById("email").value;
const nomorWa = document.getElementById("wa").value;
const message = document.getElementById("message").value;
// Reset pesan error
document.getElementById("namaError").innerText = "";
document.getElementById("emailError").innerText = "";
document.getElementById("nomorHpError").innerText = "";
document.getElementById("messageError").innerText = "";
let isValid = true;
// Validasi form
if (!nama) {
document.getElementById("namaError").innerText = "Nama wajib diisi!";
isValid = false;
}
if (!email) {
document.getElementById("emailError").innerText = "Email wajib diisi!";
isValid = false;
} else if (!/^\S+@\S+\.\S+$/.test(email)) {
document.getElementById("emailError").innerText =
"Format email tidak valid!";
isValid = false;
}
if (!nomorWa) {
document.getElementById("nomorHpError").innerText =
"Nomor HP wajib diisi!";
isValid = false;
} else if (!/^\d{10,13}$/.test(nomorWa)) {
document.getElementById("nomorHpError").innerText =
"Format nomor HP tidak valid!";
isValid = false;
}
if (!message) {
document.getElementById("messageError").innerText = "Pesan wajib diisi!";
isValid = false;
}
// jika data input valid, kirim ke whatsapp
if (isValid) {
const whatsappUrl = `https://wa.me/6282190919659?text=
Nama:%20${encodeURIComponent(nama)}%0A
Email:%20${encodeURIComponent(email)}%0A
Nomor%20HP:%20${encodeURIComponent(nomorWa)}%0A
Pesan:%20${encodeURIComponent(message)}`;
window.open(whatsappUrl, "_blank");
}
});