11.0k views
1 vote
How can we render a dropdown list in a form

User Tahlil
by
7.7k points

1 Answer

3 votes

Final answer:

To render a dropdown list in a form, use the HTML element and the element to define the choices. Retrieve the selected value using JavaScript.Explanation:To render a dropdown list in a form, you can use HTML and JavaScript. In HTML, you can use the element to create a dropdown list and the element to define the available choices. Here's an example:

<form>
<label for="dropdown">Choose a fruit:</label>
<select id="dropdown" name="fruit">
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="orange">Orange</option>
</select>
</form>

You can then use JavaScript to retrieve the selected value from the dropdown list. For example:

const dropdown = document.getElementById('dropdown');
const selectedValue = dropdown.value;
console.log(selected value); // Outputs the selected value

User Macbernie
by
7.7k points