"use strict";
const listbox = document.getElementById("list");
const tablebox = document.querySelector(".table");
//eventlistener
listbox.addEventListener("click", showTable());
function showTable() {
let childList = listbox.childNodes;
switch (childList) {
case childList[0]:
console.log("1");
tableBox.innerText += "<div>1<div>"
break;
case childList[1]:
console.log("2");
tableBox.innerText += "<div>2<div>"
break;
case childList[2]:
console.log("3");
tableBox.innerText += "<div>2<div>"
break;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div><select name="ramdom" id="list">
<option value="randummy1">1</option>
<option value="randummy2">2</option>
<option value="randummy3">3</option>
</select>
</div>
<div class="table"> </div>
<script src="/question/qusetion.js"></script>
</body>
</html>
Hello, I'm new to coding, and currently, I'm working project on my own But I'm stuck in the middle and don't know how to solve this problem. I googled it also, but I don't think I can understand what other people wrote at my level. So, I hope some people can tell me what is wrong with my code and how to solve it (If it's not much bothering you:) )
Here is what I intended:
When people choose option 1, "addeventlistenter" react and it callback "showTable" function. "showtable" function check which childNode of listbox is just activated, and if it's first option(value is randummy1) value, function gonna write "1<div" string in second div(class name is table) second and third options are gonna work in the same way too.
I tried to make the above function and wrote console.log for double-checking, but any of one is not working which means I totally failed it. If someone can explain how I was wrong and tell me how to do, it would be a big help. thankx!