-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
98 lines (82 loc) · 2.61 KB
/
main.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
const header = document.querySelector("header");
window.onscroll = function() {
if (window.scrollY > 75) {
header.classList.add("scroll");
} else {
header.classList.remove("scroll");
}
};
// code for search bar filter using JSON data.
fetch('search.json')
.then(response => response.json())
.then(data => {
const dataList = document.getElementById('searchList');
const inputSearch = document.getElementById('search');
const highlight = document.getElementById('highlight');
data.forEach(item => {
const option = document.createElement('option');
option.value = item.doctor + " - " + item.specialty;
dataList.appendChild(option);
});
inputSearch.addEventListener('input', function() {
const inputValue = inputSearch.value.toLowerCase();
let highlightText = '';
data.forEach(item => {
const optionText = (item.doctor + " - " + item.specialty).toLowerCase();
if (optionText.startsWith(inputValue)) {
highlightText = item.doctor.substring(0, inputValue.length);
}
});
highlight.innerText = highlightText;
});
inputSearch.addEventListener('keydown', function(event) {
if (event.key === "Tab" && dataList.firstChild) {
inputSearch.value = dataList.firstChild.value;
}
});
})
.catch(error => console.error('Error fetching data:', error));
// WhatsApp form submission
document
.querySelector("form")
.addEventListener("submit", function(event) {
event.preventDefault();
let name = document.getElementById("name").value;
let email = document.getElementById("email").value;
let phone = document.getElementById("phone").value;
let app = document.getElementById("app").value;
let diagnosis = document.getElementById("diagnosis").value;
let contact = "+256758185721";
let customer = name.replace(/(^\w{1})|(\s+\w{1})/g, (letter) =>
letter.toUpperCase()
);
let encodedMessage = encodeURIComponent(
"Name: " +
customer +
"\n" +
"Email: " +
email +
"\n" +
"Phone: " +
phone +
"\n" +
"Preferred App: " +
app +
"\n" +
"Diagnosis: " +
diagnosis
);
let link;
// Check if user is on a mobile device
if (
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
)
) {
link = `whatsapp://send?phone=${contact}&text=${encodedMessage}`;
} else {
// Desktop device
link = `https://web.whatsapp.com/send?phone=${contact}&text=${encodedMessage}`;
}
window.open(link, "_blank");
});