sajad torkamani
<!DOCTYPE html>
    <title>JavaScript: Get values of a multiple select box</title>
    <meta charset="UTF-8" />

    <label for="location">Select location (hold shift and select)</label> <br />
    <select name="location" id="location" multiple>
      <option value="">Anywhere</option>
      <option value="london">London</option>
      <option value="manchester">Manchester</option>
      <option value="birmingham">Birmingham</option>

    <div id="output" style="margin-top: 30px;" ;></div>

        .addEventListener('change', (event) => {
          const selectedValues = []
            .filter((option) => option.selected)
            .map((option) => option.value)

          document.querySelector('#output').innerText = selectedValues.join(
            ', '


Tagged: JavaScript

Leave a comment

Your email address will not be published. Required fields are marked *