Advertisement
Onesible

Untitled

Mar 27th, 2025
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let dropdown = document.getElementById('menu');
  3.     document.querySelector('input[type="submit"]').addEventListener('click', addOption);
  4.  
  5.     function addOption(e) {
  6.         e.preventDefault();
  7.         let text = document.getElementById('newItemText');
  8.         let value = document.getElementById('newItemValue');
  9.  
  10.         let option = document.createElement('option');
  11.         option.textContent = text.value;
  12.         option.value = value.value;
  13.  
  14.         dropdown.appendChild(option);
  15.  
  16.         text.value = '';
  17.         value.value = '';
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement