Widget:Test

Revisão de 03h17min de 23 de agosto de 2024 por Renee (discussão | contribs)

<!DOCTYPE html> <html lang="pt-BR"> <head>

   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Seleção e Exibição de Imagens</title>
   <style>
       .hidden {
           display: none;
       }
       .image-container img {
           width: 100px;
           height: 100px;
           margin: 5px;
       }
       select {
           margin: 5px;
       }
   </style>

</head> <body>

Selecione o Tipo de Mapa

   <form id="mapForm">
           <label for="mapType">Tipo de Mapa:</label>
           <select id="mapType">
               <option value="">Selecione um mapa</option>
               <option value="1">Mapa Vermelho</option>
               <option value="2">Mapa Verde</option>
               <option value="3">Mapa Roxo</option>
           </select>
   </form>
   <script>
       const specificOptions = {
           1: ['Option 1-1', 'Option 1-2', 'Option 1-3'],
           2: ['Option 2-1', 'Option 2-2', 'Option 2-3', 'Option 2-4'],
           3: ['Option 3-1', 'Option 3-2']
       };
       const images = {
           'Option 1-1': 'https://wiki.pokexgames.com/images/b/bc/BagOfPollem.png',
           'Option 1-2': 'https://wiki.pokexgames.com/images/4/43/AnotherImage.png',
           'Option 1-3': 'https://wiki.pokexgames.com/images/3/34/DifferentImage.png',
           'Option 2-1': 'https://wiki.pokexgames.com/images/c/c4/ExampleImage.png',
           'Option 2-2': 'https://wiki.pokexgames.com/images/5/56/AnotherExample.png',
           'Option 2-3': 'https://wiki.pokexgames.com/images/a/a6/SampleImage.png',
           'Option 2-4': 'https://wiki.pokexgames.com/images/d/d7/FinalExample.png',
           'Option 3-1': 'https://wiki.pokexgames.com/images/e/e8/MapType3Option1.png',
           'Option 3-2': 'https://wiki.pokexgames.com/images/f/f9/MapType3Option2.png'
       };
       document.getElementById('mapType').addEventListener('change', function() {
           const selectedMapType = this.value;
           const specificOptionSelect = document.getElementById('specificOption');
           const imageContainer = document.getElementById('imageContainer');
           
           specificOptionSelect.innerHTML = '<option value="">Selecione uma opção</option>';
           imageContainer.innerHTML = ;
           
           if (selectedMapType) {
               const options = specificOptions[selectedMapType];
               options.forEach(option => {
                   specificOptionSelect.innerHTML += `<option value="${option}">${option}</option>`;
               });
               document.getElementById('specificOptions').classList.remove('hidden');
           } else {
               document.getElementById('specificOptions').classList.add('hidden');
               document.getElementById('imageContainer').classList.add('hidden');
           }
       });
       document.getElementById('specificOption').addEventListener('change', function() {
           const selectedOption = this.value;
           const imageContainer = document.getElementById('imageContainer');
           
           imageContainer.innerHTML = ;
           
           if (selectedOption) {
               const imageUrl = images[selectedOption];
               if (imageUrl) {
                   imageContainer.innerHTML = `<img src="${imageUrl}" alt="${selectedOption}">`;
                   imageContainer.classList.remove('hidden');
               }
           } else {
               imageContainer.classList.add('hidden');
           }
       });
   </script>

</body> </html>