This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowsing.html
63 lines (62 loc) · 1.88 KB
/
browsing.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Molecule Search</title>
</head>
<body>
<h1>Molecule Search</h1>
<form>
<label>
Keyword:
<input type="text" name="keyword" required />
</label>
<br />
<label>
Filter:
<select name="filter" required>
<option value="name">Name</option>
<option value="stoichiometry">Stoichiometry</option>
<option value="date">Date</option>
<option value="smith">Smith</option>
</select>
</label>
<br />
<button type="submit">Search</button>
</form>
<hr />
<div id="result"></div>
<script>
const form = document.querySelector("form");
form.addEventListener("submit", async (event) => {
event.preventDefault();
const formData = new FormData(event.target);
const response = await fetch("/search", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
keyword: formData.get("keyword"),
filter: formData.get("filter"),
}),
});
const molecule = await response.json();
const resultDiv = document.querySelector("#result");
resultDiv.innerHTML = "";
if (molecule) {
for (const [key, value] of Object.entries(molecule)) {
const row = document.createElement("div");
const keyElem = document.createElement("span");
keyElem.textContent = key + ": ";
const valueElem = document.createElement("span");
valueElem.textContent = value;
row.appendChild(keyElem);
row.appendChild(valueElem);
resultDiv.appendChild(row);
}
} else {
resultDiv.textContent = "No results found.";
}
});
</script>
</body>
</html>