Javascript beginner here, trying to learn by doing, my question is, here i have a table which is filled with information already and below it is select tag which is fetched from url. My question is i want to fill the table again but with the information of select tag ( depending on which option user choose from select tag, table gets filled with that information). here is select tags data
[
{
"id": "1111",
"mygoals": "getmarried",
"future": "married",
},
{
"id": "2222",
"mygoals": "getmarried",
"future": "married",
},
{
"id": "33333",
"mygoals": "getmarried",
"future": "married",
}
]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<style>
</style>
</head>
<body>
<div class="container">
<table class="table table-responsive-sm ">
<thead>
<tr>
<th>id</th>
<th>mygoals</th>
<th>future</th>
</tr>
</thead>
<tbody id="t">
</tbody>
<thead>
<tr>
<th>id</th>
<th>mygoals</th>
<th>future</th>
</tr>
</thead>
<tbody id="t2">
</tbody>
</table>
<select id="Select" name="name"></select>
</div>
<script>
fetch("https://asdasd.free.beeceptor.com/a", {
method: "GET",
headers: {
"x-api-key": "p*****w"
}
}).then(res =>{
res.json().then(t => {
console.log(t);
var p ="";
var p2 ="";
p +="<tr>";
p += "<td>"+t.id+"</td>";
p += "<td>"+t.mygoals+"</td>";
p += "<td>"+t.future+"</td>";
p2 += "<td>"+t.id+"</td>";
p2 += "<td>"+t.mygoals+"</td>";
p2 += "<td>"+t.future+"</td></tr>";
document.getElementById("t").insertAdjacentHTML("beforeend", p);
document.getElementById("t2").insertAdjacentHTML("beforeend", p2);
}
)
}).catch(err => {
console.log("ERROR: " + err);
});
fetch("https:******.com/", {
method: "GET",
headers: {
"x-api-key": "p*****w"
}
}).then(res =>{
res.json().then(t => {
for (var i = 0; i < t.length; i++) {
var s = document.getElementById("Select");
var o = document.createElement("option");
option.text = t[i].id+ ' ' + t[i].mygoals;
s.add(o);
}
}
)
})
</script>
</body>
</html>
