the shares should be displayed in a list from which they can be selected.
Browse files- index.html +36 -41
index.html
CHANGED
|
@@ -53,11 +53,19 @@
|
|
| 53 |
<option value="dax">DAX</option>
|
| 54 |
</select>
|
| 55 |
</div>
|
| 56 |
-
<label class="block text-sm font-medium text-gray-700 mb-1">Stock
|
| 57 |
-
<div class="
|
| 58 |
-
<
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
</div>
|
| 62 |
</div>
|
| 63 |
|
|
@@ -295,46 +303,33 @@
|
|
| 295 |
stockSearch.value = '';
|
| 296 |
stockSearch.dispatchEvent(new Event('input'));
|
| 297 |
});
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
document.getElementById('stockSearch').addEventListener('input', function() {
|
| 301 |
const market = document.getElementById('marketSelect').value;
|
| 302 |
-
const
|
| 303 |
-
const
|
|
|
|
| 304 |
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
stock.symbol
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
}
|
| 320 |
-
|
| 321 |
-
dropdown.innerHTML = filteredStocks.map(stock => `
|
| 322 |
-
<div class="p-2 hover:bg-gray-100 cursor-pointer"
|
| 323 |
-
onclick="document.getElementById('stockSearch').value='${stock.symbol}'; this.parentNode.classList.add('hidden')">
|
| 324 |
-
<div class="font-medium">${stock.symbol}</div>
|
| 325 |
-
<div class="text-xs text-gray-500">${stock.name}</div>
|
| 326 |
-
</div>
|
| 327 |
-
`).join('');
|
| 328 |
|
| 329 |
-
|
| 330 |
-
|
| 331 |
|
| 332 |
-
//
|
| 333 |
-
document.addEventListener('
|
| 334 |
-
if (!e.target.closest('#stockDropdown') && e.target.id !== 'stockSearch') {
|
| 335 |
-
document.getElementById('stockDropdown').classList.add('hidden');
|
| 336 |
-
}
|
| 337 |
-
});
|
| 338 |
</script>
|
| 339 |
</body>
|
| 340 |
</html>
|
|
|
|
| 53 |
<option value="dax">DAX</option>
|
| 54 |
</select>
|
| 55 |
</div>
|
| 56 |
+
<label class="block text-sm font-medium text-gray-700 mb-1">Stock Selection</label>
|
| 57 |
+
<div id="stockList" class="border border-gray-300 rounded-md max-h-60 overflow-y-auto p-2">
|
| 58 |
+
<div class="grid grid-cols-1 gap-2">
|
| 59 |
+
<template id="stockItemTemplate">
|
| 60 |
+
<div class="flex items-center p-2 hover:bg-gray-50 rounded cursor-pointer">
|
| 61 |
+
<input type="radio" name="selectedStock" class="mr-2">
|
| 62 |
+
<div>
|
| 63 |
+
<div class="font-medium text-gray-800 stock-symbol"></div>
|
| 64 |
+
<div class="text-xs text-gray-500 stock-name"></div>
|
| 65 |
+
</div>
|
| 66 |
+
</div>
|
| 67 |
+
</template>
|
| 68 |
+
</div>
|
| 69 |
</div>
|
| 70 |
</div>
|
| 71 |
|
|
|
|
| 303 |
stockSearch.value = '';
|
| 304 |
stockSearch.dispatchEvent(new Event('input'));
|
| 305 |
});
|
| 306 |
+
// Populate stock list
|
| 307 |
+
function populateStockList() {
|
|
|
|
| 308 |
const market = document.getElementById('marketSelect').value;
|
| 309 |
+
const stockList = document.getElementById('stockList');
|
| 310 |
+
const template = document.getElementById('stockItemTemplate');
|
| 311 |
+
const container = stockList.querySelector('.grid');
|
| 312 |
|
| 313 |
+
container.innerHTML = '';
|
| 314 |
+
|
| 315 |
+
stockData[market].forEach(stock => {
|
| 316 |
+
const clone = template.content.cloneNode(true);
|
| 317 |
+
const radio = clone.querySelector('input[type="radio"]');
|
| 318 |
+
radio.value = stock.symbol;
|
| 319 |
+
radio.id = `stock-${stock.symbol}`;
|
| 320 |
+
|
| 321 |
+
clone.querySelector('.stock-symbol').textContent = stock.symbol;
|
| 322 |
+
clone.querySelector('.stock-name').textContent = stock.name;
|
| 323 |
+
|
| 324 |
+
container.appendChild(clone);
|
| 325 |
+
});
|
| 326 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
|
| 328 |
+
// Initialize stock list
|
| 329 |
+
populateStockList();
|
| 330 |
|
| 331 |
+
// Update stock list when market changes
|
| 332 |
+
document.getElementById('marketSelect').addEventListener('change', populateStockList);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
</script>
|
| 334 |
</body>
|
| 335 |
</html>
|