I`ve been trying to work out how to fix this problem in vain.
Here the below code works fine. However, in jsfiddle nothing happens as well as in HTML file.
I don`t know what is wrong with it. Could anyone please show me how I can fix it?
function selectItems() {
var myDiv = document.getElementById("car-select");
var array = ["McLaren", "Ferrari", "Mercedes"];
var selectList = document.createElement("select");
selectList.setAttribute("id", "Car");
myDiv.appendChild(selectList);
for (var i = 0; i < array.length; i++) {
var option = document.createElement("option");
option.setAttribute("value", array[i]);
option.text = array[i];
selectList.appendChild(option);
}
var myDiv2 = document.getElementById("tyre-select");
var array2 = ["Bridgestone", "Michelin", "Continental"];
var selectList2 = document.createElement("select");
selectList2.setAttribute("id", "Eng");
myDiv2.appendChild(selectList2);
for (var i = 0; i < array2.length; i++) {
var option2 = document.createElement("option");
option2.setAttribute("value", array2[i]);
option2.text = array2[i];
selectList2.appendChild(option2);
}
}
<body class="car-showing" onload="selectItems()">
<div id="PPMCar">
<form method="post">
<ul>
<li class="engine-item">
<div class="engine-details-name">
<a class="race-team">Race Team</a>
<ul class="car-attributes">
<div id="car-select">
<li>#1:</li>
</div>
<div id="tyre-select">
<li>#2:</li>
</div>
</ul>
</div>
</li>
</ul>
</form>
</div>
</body>