Skip to content

Instantly share code, notes, and snippets.

@mdibrahimk48
Created September 11, 2023 05:30
Show Gist options
  • Save mdibrahimk48/8fa0513e76286064e31073111f92a4f3 to your computer and use it in GitHub Desktop.
Save mdibrahimk48/8fa0513e76286064e31073111f92a4f3 to your computer and use it in GitHub Desktop.
To display the selected data from a dropdown menu, you typically use a <select> element for the dropdown and another element, such as a <span>, to display the selected value. Here’s an example of how you can display the selected data correctly:
<label for="pick-up">Pick-up Location:</label>
<select id="pick-up" name="pick-up">
<option value="">Select an option</option>
<option value="Airport Ngurah Rai">Airport Ngurah Rai</option>
<option value="Amed">Amed</option>
<!-- Add more options here -->
</select>
Selected Pick-up Location: <span id="selected-pick-up"></span>
<script>
const pickUpSelect = document.getElementById('pick-up');
const selectedPickUp = document.getElementById('selected-pick-up');
pickUpSelect.addEventListener('change', function() {
selectedPickUp.textContent = pickUpSelect.value;
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment