-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
91 lines (67 loc) · 2.84 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>FORMULARIO</title>
</head>
<body>
<div id="root">
<form id="myform" action="/subir" method="post">
<select id="selectSites" name="selectSites" onchange="getCategories()"></select><br>
<select id="selectCategories" name="selectCategories"></select><br>
Columnas <input type="text" name="columnas"><br>
Filas <input type="text" name="filas"><br>
<input type="submit" value="Submit">
</form>
</div>
<script>
var request = new XMLHttpRequest();
request.open('GET', 'https://api.mercadolibre.com/sites', true);
request.onload = function () {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400) {
var select = document.getElementById("selectSites")
data.forEach(site => {
var option = document.createElement("option")
option.setAttribute("value", site.id)
option.innerText = site.name
select.appendChild(option)
});
} else {
const errorMessage = document.createElement('marquee');
errorMessage.textContent = "No funciona!";
app.appendChild(errorMessage);
}
}
request.send();
function getCategories(){
var selectSites = document.getElementById("selectSites")
var selectCategories = document.getElementById("selectCategories")
while(selectCategories.firstChild) {
selectCategories.removeChild(selectCategories.firstChild);
}
var request = new XMLHttpRequest();
request.open('GET', 'https://api.mercadolibre.com/sites/'+ selectSites.value +'/categories', true);
request.onload = function () {
// Begin accessing JSON data here
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400) {
var select = document.getElementById("selectCategories")
data.forEach(category => {
var option = document.createElement("option")
option.setAttribute("value", category.id)
option.innerText = category.name
select.appendChild(option)
});
} else {
const errorMessage = document.createElement('marquee');
errorMessage.textContent = "No funciona!";
app.appendChild(errorMessage);
}
}
request.send();
}
</script>
</body>
</html>